radar-ananke 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.markdown +17 -0
- data/Rakefile +81 -0
- data/lib/ananke.rb +45 -0
- data/rails/init.rb +1 -0
- data/spec/ananke_spec.rb +48 -0
- data/spec/spec_helper.rb +16 -0
- metadata +59 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Ananke
|
|
2
|
+
|
|
3
|
+
Lets you use .NET styled time formats in Ruby.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install this as a gem using
|
|
8
|
+
|
|
9
|
+
sudo gem install radar-ananke --source http://gems.github.com
|
|
10
|
+
|
|
11
|
+
Or as a plugin
|
|
12
|
+
|
|
13
|
+
script/plugin install git://github.com/radar/ananke.git
|
|
14
|
+
|
|
15
|
+
## Example(s)
|
|
16
|
+
|
|
17
|
+
Time.now.alt_strftime("dd/mm/yyyy hh:mm:ss") => "01/01/2009 12:01:01"
|
data/Rakefile
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
desc "generates .gemspec file"
|
|
2
|
+
task :gemspec => "version:read" do
|
|
3
|
+
spec = Gem::Specification.new do |gem|
|
|
4
|
+
gem.name = "by_star"
|
|
5
|
+
gem.summary = "ActiveRecord extension for easier date scopes and time ranges"
|
|
6
|
+
gem.email = "mislav.marohnic@gmail.com"
|
|
7
|
+
gem.homepage = "http://github.com/mislav/by_star"
|
|
8
|
+
gem.authors = ["Mislav Marohnić", "Ryan Bigg"]
|
|
9
|
+
gem.has_rdoc = true
|
|
10
|
+
|
|
11
|
+
gem.version = GEM_VERSION
|
|
12
|
+
gem.files = FileList['Rakefile', '{lib,spec,rails}/**/*', 'README*', '*LICENSE*'].reject do |file|
|
|
13
|
+
File.directory?(file)
|
|
14
|
+
end
|
|
15
|
+
gem.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
spec_string = spec.to_ruby
|
|
19
|
+
|
|
20
|
+
begin
|
|
21
|
+
Thread.new { eval("$SAFE = 3\n#{spec_string}", binding) }.join
|
|
22
|
+
rescue
|
|
23
|
+
abort "unsafe gemspec: #{$!}"
|
|
24
|
+
else
|
|
25
|
+
File.open("#{spec.name}.gemspec", 'w') { |file| file.write spec_string }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
begin
|
|
30
|
+
require 'spec'
|
|
31
|
+
rescue LoadError
|
|
32
|
+
require 'rubygems'
|
|
33
|
+
require 'spec'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
require 'rake/rdoctask'
|
|
37
|
+
require 'spec/rake/spectask'
|
|
38
|
+
desc 'Default: run unit tests.'
|
|
39
|
+
task :default => :spec
|
|
40
|
+
|
|
41
|
+
desc "Run the specs under spec"
|
|
42
|
+
Spec::Rake::SpecTask.new do |t|
|
|
43
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
|
44
|
+
t.libs = %w(lib spec)
|
|
45
|
+
t.spec_opts << "-c"
|
|
46
|
+
t.ruby_opts << "-rubygems"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
desc 'Generate documentation for the by_star plugin.'
|
|
50
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
52
|
+
rdoc.title = 'ByStar'
|
|
53
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
54
|
+
rdoc.rdoc_files.include('README')
|
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
task :bump => ["version:bump", :gemspec]
|
|
59
|
+
|
|
60
|
+
namespace :version do
|
|
61
|
+
task :read do
|
|
62
|
+
unless defined? GEM_VERSION
|
|
63
|
+
GEM_VERSION = File.read("VERSION")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
task :bump => :read do
|
|
68
|
+
if ENV['VERSION']
|
|
69
|
+
GEM_VERSION.replace ENV['VERSION']
|
|
70
|
+
else
|
|
71
|
+
GEM_VERSION.sub!(/\d+$/) { |num| num.to_i + 1 }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
File.open("VERSION", 'w') { |v| v.write GEM_VERSION }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
task :release => :bump do
|
|
79
|
+
system %(git add VERSION *.gemspec && git commit -m "release v#{GEM_VERSION}")
|
|
80
|
+
system %(git tag -am "release v#{GEM_VERSION}" v#{GEM_VERSION})
|
|
81
|
+
end
|
data/lib/ananke.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class Time
|
|
2
|
+
def alt_strftime(format)
|
|
3
|
+
conversions = { 'dddd' => '%A',
|
|
4
|
+
'ddd' => '%a',
|
|
5
|
+
'dd' => '%d',
|
|
6
|
+
'd' => short('d'),
|
|
7
|
+
'h' => '%I',
|
|
8
|
+
'hh' => '%I',
|
|
9
|
+
'H' => '%H',
|
|
10
|
+
'HH' => '%H',
|
|
11
|
+
'K' => '%Z',
|
|
12
|
+
'm' => short('M'),
|
|
13
|
+
'mm' => '%M',
|
|
14
|
+
'M' => short('m'),
|
|
15
|
+
'MM' => '%m',
|
|
16
|
+
'MMM' => '%b',
|
|
17
|
+
'MMMM' => '%B',
|
|
18
|
+
'ss' => '%S',
|
|
19
|
+
's' => short('S'),
|
|
20
|
+
't' => strftime("%p")[0],
|
|
21
|
+
'tt' => "%p",
|
|
22
|
+
'y' => short('y'),
|
|
23
|
+
'yy' => "%y",
|
|
24
|
+
'yyy' => (year < 1000 ? strftime("%Y")[1..3] : strftime("%Y")),
|
|
25
|
+
'yyyy' => strftime("%Y"),
|
|
26
|
+
'yyyyy' => strftime("%Y"),
|
|
27
|
+
'\'' => '',
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
output = ''
|
|
32
|
+
|
|
33
|
+
format.split(/\b/).each do |part|
|
|
34
|
+
output << (conversions[part] || part)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
strftime(output)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def short(format)
|
|
43
|
+
strftime("%#{format}").to_i.to_s
|
|
44
|
+
end
|
|
45
|
+
end
|
data/rails/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'ananke'
|
data/spec/ananke_spec.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "Ananke" do
|
|
4
|
+
before do
|
|
5
|
+
stub_time
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def work
|
|
9
|
+
Time.now.alt_strftime(description_args.first)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
[["dddd", "full day name", "Tuesday"],
|
|
13
|
+
["ddd", "abbreviated day name", "Tue"],
|
|
14
|
+
["dd", "long day numerical", "01"],
|
|
15
|
+
["d", "short day numerical", "1"],
|
|
16
|
+
["h", "short hour numerical", "12"],
|
|
17
|
+
["hh", "long hour numerical", "12"],
|
|
18
|
+
["K", "timezone information", "UTC"],
|
|
19
|
+
["m", "short minute", "1"],
|
|
20
|
+
["mm", "long minutes", "01"],
|
|
21
|
+
["M", "short month", "9"],
|
|
22
|
+
["MM", "long month", "09"],
|
|
23
|
+
["MMM", "abbreviated month name", "Sep"],
|
|
24
|
+
["MMMM", "long month name", "September"],
|
|
25
|
+
["s", "short seconds", "1"],
|
|
26
|
+
["ss", "long seconds", "01"],
|
|
27
|
+
["t", "first character ordinal", "P"],
|
|
28
|
+
["tt", "full ordinal", "PM"],
|
|
29
|
+
["y", "short year", "9"],
|
|
30
|
+
["yy", "long short year", "09"],
|
|
31
|
+
["yyy", "maybe medium year", "2009"],
|
|
32
|
+
["yyyy", "long year", "2009"],
|
|
33
|
+
["yyyyy", "longest year", "2009"],
|
|
34
|
+
["dd/mm/yyyy hh:mm:ss", "full year, short month, long day", "01/01/2009 12:01:01"],
|
|
35
|
+
["dd'mm'yyyy hh'mm'ss", "anarchy", "01012009 120101"]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
].each do |name, title, expected|
|
|
41
|
+
|
|
42
|
+
describe name do
|
|
43
|
+
it title do
|
|
44
|
+
work.should eql(expected)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'activerecord'
|
|
3
|
+
|
|
4
|
+
$:.unshift(File.join(File.dirname(__FILE__), "../lib"))
|
|
5
|
+
|
|
6
|
+
require 'activesupport'
|
|
7
|
+
require 'ananke'
|
|
8
|
+
require 'spec'
|
|
9
|
+
|
|
10
|
+
def stub_time(day=01, month=9, year=Time.now.year, hour=12, minute=01, second=01)
|
|
11
|
+
Time.stub!(:now).and_return("#{day}-#{month}-#{year} #{hour}:#{minute}:#{second}".to_time)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# bootstraping the plugin through init.rb
|
|
15
|
+
# tests how it would load in a real application
|
|
16
|
+
load File.dirname(__FILE__) + "/../rails/init.rb"
|
metadata
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: radar-ananke
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ryan Bigg
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-05-26 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
email: radarlistener@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- Rakefile
|
|
26
|
+
- lib/ananke.rb
|
|
27
|
+
- spec/ananke_spec.rb
|
|
28
|
+
- spec/spec_helper.rb
|
|
29
|
+
- rails/init.rb
|
|
30
|
+
- README.markdown
|
|
31
|
+
- MIT-LICENSE
|
|
32
|
+
has_rdoc: false
|
|
33
|
+
homepage: http://github.com/radar/ananke
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: "0"
|
|
44
|
+
version:
|
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: "0"
|
|
50
|
+
version:
|
|
51
|
+
requirements: []
|
|
52
|
+
|
|
53
|
+
rubyforge_project:
|
|
54
|
+
rubygems_version: 1.2.0
|
|
55
|
+
signing_key:
|
|
56
|
+
specification_version: 3
|
|
57
|
+
summary: Converts .Net formats to strftime formats
|
|
58
|
+
test_files: []
|
|
59
|
+
|