fuzzyclock 0.0.1 → 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/Rakefile CHANGED
@@ -1,2 +1,19 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ #
5
+ # Rspec
6
+ #
7
+
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
14
+ spec.pattern = 'spec/**/*_spec.rb'
15
+ spec.rcov = true
16
+ spec.rcov_opts = ['--exclude', 'spec']
17
+ end
18
+
19
+ task :default => :spec
data/bin/fuzzyclock CHANGED
@@ -17,9 +17,7 @@ class FuzzyClockCommand
17
17
  end
18
18
 
19
19
  def execute
20
- t = FuzzyClock.new
21
- print "It's about " if options[:about]
22
- puts t.to_s
20
+ puts FuzzyClock.parse(nil, options)
23
21
  end
24
22
 
25
23
  def parse_options
@@ -29,6 +27,19 @@ class FuzzyClockCommand
29
27
  opts.on("-a", "--about", "Say about?") do |v|
30
28
  self.options[:about] = v
31
29
  end
30
+
31
+ opts.on("-l", "--locale [lang]", String, "Langage") do |v|
32
+ self.options[:locale] = v
33
+ end
34
+
35
+ opts.on("-U", "--uppercase", "UPPERCASE OUTPUT") do |v|
36
+ self.options[:upcase] = v
37
+ end
38
+
39
+ opts.on("-C", "--capitalize", "Capitalize Output") do |v|
40
+ self.options[:capitalize] = v
41
+ end
42
+
32
43
  }.parse!
33
44
  end
34
45
 
data/fuzzyclock.gemspec CHANGED
@@ -18,4 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'rspec', '>= 2.5.0'
23
+
21
24
  end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ class FuzzyClock
4
+ @@locales ||= {}
5
+ @@locales[:en] = {
6
+ :about => "it's about %t",
7
+ :hour => {
8
+ 0 => "twelve",
9
+ 1 => "one",
10
+ 2 => "two",
11
+ 3 => "three",
12
+ 4 => "four",
13
+ 5 => "five",
14
+ 6 => "six",
15
+ 7 => "seven",
16
+ 8 => "eight",
17
+ 9 => "nine",
18
+ 10 => "ten",
19
+ 11 => "eleven",
20
+ 12 => "twelve",
21
+ },
22
+ :min => {
23
+ 0..0 => "%0 o'clock",
24
+ 1..2 => "a bit after %0",
25
+ 3..7 => "five past %0",
26
+ 8..12 => "ten past %0",
27
+ 13..17 => "quarter past %0",
28
+ 18..22 => "twenty past %0",
29
+ 23..27 => "twenty five past %0",
30
+ 28..32 => ["half past %0", "%0 thirty"],
31
+ 33..37 => "twenty five to %1",
32
+ 38..42 => "twenty to %1",
33
+ 43..47 => "quarter to %1",
34
+ 48..52 => "ten to %1",
35
+ 53..57 => "five to %1",
36
+ 58..59 => ["almost %1", "nearly %1"]
37
+ }
38
+ }
39
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ class FuzzyClock
4
+ @@locales ||= {}
5
+ @@locales[:se] = {
6
+ :about => "runt %t",
7
+ :hour => {
8
+ 0 => "tolv",
9
+ 1 => "ett",
10
+ 2 => "två",
11
+ 3 => "tree",
12
+ 4 => "fyra",
13
+ 5 => "fem",
14
+ 6 => "sex",
15
+ 7 => "sju",
16
+ 8 => "åtta",
17
+ 9 => "nio",
18
+ 10 => "tio",
19
+ 11 => "elva",
20
+ 12 => "tolv",
21
+ },
22
+ :min => {
23
+ 0..0 => "klockan %0",
24
+ 1..2 => "lite efter %0",
25
+ 3..7 => "fem över %0",
26
+ 8..12 => "tio över %0",
27
+ 13..17 => "kvart över %0",
28
+ 18..22 => "tjugo över %0",
29
+ 23..27 => "tjugofem över %0",
30
+ 28..32 => ["halv %1", "%0 och tretti"],
31
+ 33..37 => "tjugofem i %1",
32
+ 38..42 => "tjugo i %1",
33
+ 43..47 => "kvart i %1",
34
+ 48..52 => "tio i %1",
35
+ 53..57 => "fem i %1",
36
+ 58..59 => ["nästan %1", "strax före %1"]
37
+ }
38
+ }
39
+ end
@@ -1,3 +1,3 @@
1
1
  class Fuzzyclock
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/fuzzyclock.rb CHANGED
@@ -1,61 +1,56 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'fuzzyclock/locale/en'
4
+ require 'fuzzyclock/locale/se'
3
5
  require 'fuzzyclock/version'
4
6
 
5
7
  class FuzzyClock
6
- @@HourToString = {
7
- 0 => "twelve",
8
- 1 => "one",
9
- 2 => "two",
10
- 3 => "three",
11
- 4 => "four",
12
- 5 => "five",
13
- 6 => "six",
14
- 7 => "seven",
15
- 8 => "eight",
16
- 9 => "nine",
17
- 10 => "ten",
18
- 11 => "eleven",
19
- 12 => "twelve",
20
- }
21
-
22
- attr_writer :time
23
-
24
- def initialize(time=Time.now)
25
- @time = time
8
+
9
+ class UnsupportedLocale < ArgumentError; end
10
+
11
+ @@locales ||= {}
12
+
13
+ def self.parse(time, opts = {})
14
+ self.new(time, opts).to_s
26
15
  end
27
-
28
- # :s = suffix, :p = prefix
29
- def fuzziness(min=0)
30
- case min
31
- when 0 then [:s, "o'clock"]
32
- when 1..2 then [:p, "a bit after"]
33
- when 3..7 then [:p, "five past"]
34
- when 8..12 then [:p, "ten past"]
35
- when 13..17 then [:p, "quarter past"]
36
- when 18..22 then [:p, "twenty past"]
37
- when 23..27 then [:p, "twenty five past"]
38
- when 28..32 then rand(2) == 0 ? [:p, "half past"] : [:s, "thirty"]
39
- when 33..37 then [:p, "twenty five to"]
40
- when 38..42 then [:p, "twenty to"]
41
- when 43..47 then [:p, "quarter to"]
42
- when 48..52 then [:p, "ten to"]
43
- when 53..57 then [:p, "five to"]
44
- when 58..59 then rand(2) == 0 ? [:p, "almost"] : [:p, "nearly"]
45
- end
16
+
17
+ attr_accessor :time
18
+ attr_accessor :locale
19
+ attr_accessor :about
20
+ attr_accessor :capitalize
21
+ attr_accessor :upcase
22
+
23
+ def initialize(time = nil, opts = {})
24
+ @time = time || Time.now
25
+ @locale = opts[:locale] || :en
26
+ @about = opts[:about] || false
27
+ @capitalize = opts[:capitalize] || false
28
+ @upcase = opts[:upcase] || false
46
29
  end
47
-
48
- def to_s
49
- hr, min = @time.hour, @time.min
50
- if (33..59) === min
51
- hr += 1
52
- end
53
- str = @@HourToString[hr % 12]
54
- fuzz = fuzziness(min)
55
- if fuzz[0] == :p
56
- str = fuzz[1] + " " + str
57
- elsif fuzz[0] == :s
58
- str = str + " " + fuzz[1]
30
+
31
+ def parse
32
+ raise UnsupportedLocale, %Q{Locale "#{@locale}" is not supported.} unless @@locales.has_key?(@locale.to_sym)
33
+ lang = @@locales[@locale.to_sym]
34
+
35
+ this_hour = lang[:hour][@time.hour % 12]
36
+ next_hour = lang[:hour][@time.hour % 12 + 1]
37
+
38
+ fuzz = nil
39
+ lang[:min].each do |range, value|
40
+ if range.include?(@time.min)
41
+ fuzz = value.is_a?(Array) ? value[rand(value.size)] : value
42
+ end
59
43
  end
44
+
45
+ fuzz.gsub!('%0', this_hour)
46
+ fuzz.gsub!('%1', next_hour)
47
+
48
+ fuzz = lang[:about].gsub('%t', fuzz) if @about
49
+ fuzz.capitalize! if @capitalize
50
+ fuzz.upcase! if @upcase
51
+
52
+ fuzz
60
53
  end
54
+ alias :to_s :parse
55
+
61
56
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuzzyclock
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Grover
@@ -16,10 +16,25 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-15 00:00:00 +01:00
19
+ date: 2011-04-16 00:00:00 +01:00
20
20
  default_executable:
21
- dependencies: []
22
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 27
31
+ segments:
32
+ - 2
33
+ - 5
34
+ - 0
35
+ version: 2.5.0
36
+ type: :development
37
+ version_requirements: *id001
23
38
  description: A Ruby class to imitate the basic functionality of the cool FuzzyClock application
24
39
  email:
25
40
  executables:
@@ -36,6 +51,8 @@ files:
36
51
  - bin/fuzzyclock
37
52
  - fuzzyclock.gemspec
38
53
  - lib/fuzzyclock.rb
54
+ - lib/fuzzyclock/locale/en.rb
55
+ - lib/fuzzyclock/locale/se.rb
39
56
  - lib/fuzzyclock/version.rb
40
57
  has_rdoc: true
41
58
  homepage: https://github.com/samgrover/fuzzyclock.rb