rtm-time 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "rspec"
9
+ gem "bundler"
10
+ gem "jeweler"
11
+ gem "rcov", ">= 0"
12
+ end
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.2.2)
11
+ rcov (0.9.11)
12
+ rspec (2.7.0)
13
+ rspec-core (~> 2.7.0)
14
+ rspec-expectations (~> 2.7.0)
15
+ rspec-mocks (~> 2.7.0)
16
+ rspec-core (2.7.1)
17
+ rspec-expectations (2.7.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.7.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler
26
+ jeweler
27
+ rcov
28
+ rspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 wtnabe
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.
@@ -0,0 +1,19 @@
1
+ = rtm-time
2
+
3
+ A simple parser for RTM's estimate time string
4
+
5
+ == Contributing to rtm-time
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 wtnabe. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,51 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rtm-time"
18
+ gem.homepage = "http://github.com/wtnabe/rtm-time"
19
+ gem.license = "BSD"
20
+ gem.summary = %Q{A parser for RTM's estimate time}
21
+ gem.description = %Q{parse and inspect RTM's estimate time}
22
+ gem.email = "wtnabe@gmail.com"
23
+ gem.authors = ["wtnabe"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ RDoc::Task.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "rtm-time #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
50
+
51
+ load File.dirname(__FILE__) + '/tasks/git.rake'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rtm_time"
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $KCODE = 'u' unless defined? ::Encoding
4
+
5
+ module RtmTime
6
+ attr_reader :day, :hour, :min
7
+
8
+ def self.extended( obj )
9
+ obj.class_eval {
10
+ def obj.parse( time_str )
11
+ self.new.parse( time_str )
12
+ end
13
+ }
14
+ end
15
+
16
+ #
17
+ # [param] String time_str
18
+ #
19
+ # 解釈できない場合、エラーがユーザーに feedback されるケースと単に無
20
+ # 視されるケースがある
21
+ #
22
+ def parse( time_str )
23
+ @day = nil
24
+ @hour = nil
25
+ @min = nil
26
+
27
+ parsed = time_str.scan(/(?:([0-9\.]+)\s*([^0-9]+|\z))/u)
28
+
29
+ if parsed.size > 0
30
+ # d, h, m の順番にも縛りはない
31
+ parsed.each { |num, unit|
32
+ assort( num, unit )
33
+ }
34
+ @day = @day.to_i
35
+ @min = (@min.to_i + ((@hour || 0) - @hour.to_i) * 60).round
36
+ @hour = @hour.to_i
37
+ end
38
+
39
+ self
40
+ end
41
+
42
+ #
43
+ # [return] Array
44
+ #
45
+ def to_a
46
+ [day, hour, min]
47
+ end
48
+
49
+ #
50
+ # [return] Hash
51
+ #
52
+ def to_h
53
+ {:day => day, :hour => hour, :min => min}
54
+ end
55
+ alias_method :to_hash, :to_h
56
+ end
57
+
58
+ Dir.glob( File.dirname(__FILE__) + '/**/*.rb' ).each { |f|
59
+ require f.sub( /\.rb\z/, '' )
60
+ }
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ module RtmTime
3
+ class En
4
+ include RtmTime
5
+ self.extend( RtmTime )
6
+
7
+ #
8
+ # [param] String num
9
+ # [param] String unit
10
+ #
11
+ def assort( num, unit )
12
+ case unit
13
+ when /\Ad/u
14
+ @day ||= num.to_i
15
+ when /\Ah/u
16
+ @hour ||= num.to_f
17
+ when /\Am/u
18
+ @min ||= num.to_i
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/en'
3
+
4
+ module RtmTime
5
+ class Ja < En
6
+ #
7
+ # [param] String num
8
+ # [param] String unit
9
+ #
10
+ def assort( num, unit )
11
+ super
12
+ case unit
13
+ when /\A日/u
14
+ @day ||= num.to_i
15
+ when /\A時/u
16
+ @hour ||= num.to_f
17
+ when /\A分/u
18
+ @min ||= num.to_i
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rtm-time}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{wtnabe}]
12
+ s.date = %q{2011-12-09}
13
+ s.description = %q{parse and inspect RTM's estimate time}
14
+ s.email = %q{wtnabe@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/rtm-time.rb",
29
+ "lib/rtm_time.rb",
30
+ "lib/rtm_time/en.rb",
31
+ "lib/rtm_time/ja.rb",
32
+ "rtm-time.gemspec",
33
+ "spec/rtm_time/en_spec.rb",
34
+ "spec/rtm_time/ja_spec.rb",
35
+ "spec/spec_helper.rb",
36
+ "tasks/git.rake"
37
+ ]
38
+ s.homepage = %q{http://github.com/wtnabe/rtm-time}
39
+ s.licenses = [%q{BSD}]
40
+ s.require_paths = [%q{lib}]
41
+ s.rubygems_version = %q{1.8.6}
42
+ s.summary = %q{A parser for RTM's estimate time}
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<rspec>, [">= 0"])
54
+ s.add_dependency(%q<bundler>, [">= 0"])
55
+ s.add_dependency(%q<jeweler>, [">= 0"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, [">= 0"])
61
+ s.add_dependency(%q<jeweler>, [">= 0"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,82 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe RtmTime::En do
5
+ describe 'only integer' do
6
+ context '2h15m' do
7
+ subject {
8
+ RtmTime::En.parse( '2h15m' )
9
+ }
10
+ it {
11
+ subject.to_hash.should == {:day => 0, :hour => 2, :min => 15}
12
+ }
13
+ it {
14
+ subject.to_a.should == [0, 2, 15]
15
+ }
16
+ end
17
+
18
+ context ' 2 hrs 15 min ' do
19
+ subject {
20
+ RtmTime::En.parse( ' 2 hrs 15 min ' )
21
+ }
22
+ it {
23
+ subject.to_h.should == {:day => 0, :hour => 2, :min => 15}
24
+ }
25
+ it {
26
+ subject.to_a.should == [0, 2, 15]
27
+ }
28
+ end
29
+
30
+ context '1d 2h' do
31
+ subject {
32
+ RtmTime::En.parse('1d 2h')
33
+ }
34
+ it {
35
+ subject.to_h.should == {:day => 1, :hour => 2, :min => 0}
36
+ }
37
+ it {
38
+ subject.to_a.should == [1, 2, 0]
39
+ }
40
+ end
41
+ end
42
+
43
+ describe 'float' do
44
+ context '1.2h' do
45
+ subject {
46
+ RtmTime::En.parse( '1.2h' ).to_h
47
+ }
48
+ it {
49
+ should == {:day => 0, :hour => 1, :min => 12}
50
+ }
51
+ end
52
+
53
+ context '1h' do
54
+ subject {
55
+ RtmTime::En.parse( '1h' ).to_h
56
+ }
57
+ it {
58
+ should == {:day => 0, :hour => 1, :min => 0}
59
+ }
60
+ end
61
+
62
+ context '10m 1.5h ' do
63
+ subject {
64
+ RtmTime::En.parse( '10m 1.5h ' ).to_h
65
+ }
66
+ it {
67
+ should = {:day => 0, :hour => 1, :min => 40}
68
+ }
69
+ end
70
+ end
71
+
72
+ describe 'unsupported' do
73
+ context '1.2時間' do
74
+ subject {
75
+ RtmTime::En.parse( '1.2時間' ).to_h
76
+ }
77
+ it {
78
+ should == {:day => 0, :hour => 0, :min => 0}
79
+ }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe RtmTime::Ja do
5
+ describe 'onle integer' do
6
+ context '2時間および15分' do
7
+ subject {
8
+ RtmTime::Ja.parse( '2時間および15分' ).to_h
9
+ }
10
+ it {
11
+ should == {:day => 0, :hour => 2 , :min => 15}
12
+ }
13
+ end
14
+
15
+ context '15分と2時間' do
16
+ subject {
17
+ RtmTime::Ja.parse( '15分と2時間' ).to_h
18
+ }
19
+ it {
20
+ should == {:day => 0, :hour => 2, :min => 15}
21
+ }
22
+ end
23
+
24
+ context '8h分と2m時間' do
25
+ subject {
26
+ RtmTime::Ja.parse( '8h分と2時間m' ).to_h
27
+ }
28
+ # first in
29
+ it {
30
+ should == {:day => 0, :hour => 8, :min => 0}
31
+ }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rtm-time'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,8 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ namespace :git do
4
+ desc 'list untracked files'
5
+ task :untracked do
6
+ sh "git ls-files -o -X #{File.dirname(__FILE__) + '/../.gitignore'}"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtm-time
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - wtnabe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &3859620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *3859620
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &3859370 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *3859370
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &3859120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *3859120
47
+ - !ruby/object:Gem::Dependency
48
+ name: rcov
49
+ requirement: &3858870 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *3858870
58
+ description: parse and inspect RTM's estimate time
59
+ email: wtnabe@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - LICENSE.txt
64
+ - README.rdoc
65
+ files:
66
+ - .document
67
+ - .rspec
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ - Rakefile
73
+ - VERSION
74
+ - lib/rtm-time.rb
75
+ - lib/rtm_time.rb
76
+ - lib/rtm_time/en.rb
77
+ - lib/rtm_time/ja.rb
78
+ - rtm-time.gemspec
79
+ - spec/rtm_time/en_spec.rb
80
+ - spec/rtm_time/ja_spec.rb
81
+ - spec/spec_helper.rb
82
+ - tasks/git.rake
83
+ homepage: http://github.com/wtnabe/rtm-time
84
+ licenses:
85
+ - BSD
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: 933625971
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.6
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A parser for RTM's estimate time
111
+ test_files: []