fuzzyclock 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fuzzyclock.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # fuzzyclock.rb #
2
+
3
+ Class to imitate the basic functionality of the cool FuzzyClock application at http://www.objectpark.org/FuzzyClock.html
4
+ e.g. 10:34 is shown as "twenty five to eleven"
5
+
6
+
7
+ ## Installation ##
8
+
9
+ gem install fuzzyclock
10
+
11
+
12
+ ## Usage ##
13
+
14
+ $ fuzzyclock
15
+ twenty to four
16
+ $ fuzzyclock -a
17
+ It's about twenty to four
18
+ $ fuzzyclock --help
19
+ Usage: fuzzyclock [options]
20
+ -a, --about Say about?
21
+
22
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/fuzzyclock ADDED
@@ -0,0 +1,37 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'fuzzyclock'
5
+ require 'optparse'
6
+
7
+ class FuzzyClockCommand
8
+
9
+ def self.run
10
+ fc = self.new
11
+ fc.parse_options
12
+ fc.execute
13
+ end
14
+
15
+ def options
16
+ @options ||= {}
17
+ end
18
+
19
+ def execute
20
+ t = FuzzyClock.new
21
+ print "It's about " if options[:about]
22
+ puts t.to_s
23
+ end
24
+
25
+ def parse_options
26
+ OptionParser.new { |opts|
27
+ opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
28
+
29
+ opts.on("-a", "--about", "Say about?") do |v|
30
+ self.options[:about] = v
31
+ end
32
+ }.parse!
33
+ end
34
+
35
+ end
36
+
37
+ FuzzyClockCommand.run
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fuzzyclock/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fuzzyclock"
7
+ s.version = Fuzzyclock::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Sam Grover', 'Jim Myhrberg']
10
+ # s.email = ["TODO: Write your email address"]
11
+ s.homepage = 'https://github.com/samgrover/fuzzyclock.rb'
12
+ s.summary = 'A Ruby class to imitate the basic functionality of the cool FuzzyClock application'
13
+ s.description = 'A Ruby class to imitate the basic functionality of the cool FuzzyClock application'
14
+
15
+ s.rubyforge_project = "fuzzyclock"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,3 @@
1
+ class Fuzzyclock
2
+ VERSION = '0.0.1'
3
+ end
data/lib/fuzzyclock.rb ADDED
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ require 'fuzzyclock/version'
4
+
5
+ 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
26
+ 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
46
+ 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]
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fuzzyclock
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sam Grover
14
+ - Jim Myhrberg
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-04-15 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: A Ruby class to imitate the basic functionality of the cool FuzzyClock application
24
+ email:
25
+ executables:
26
+ - fuzzyclock
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - bin/fuzzyclock
37
+ - fuzzyclock.gemspec
38
+ - lib/fuzzyclock.rb
39
+ - lib/fuzzyclock/version.rb
40
+ has_rdoc: true
41
+ homepage: https://github.com/samgrover/fuzzyclock.rb
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: fuzzyclock
70
+ rubygems_version: 1.6.1
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: A Ruby class to imitate the basic functionality of the cool FuzzyClock application
74
+ test_files: []
75
+