timeparser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +1 -0
- data/Gemfile +7 -0
- data/Rakefile +7 -0
- data/lib/timeparser/timeparsing.treetop +38 -0
- data/lib/timeparser/version.rb +3 -0
- data/lib/timeparser.rb +16 -0
- data/spec/lib/timeparser_spec.rb +25 -0
- data/spec/spec_helper.rb +5 -0
- data/timeparser.gemspec +22 -0
- metadata +68 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2-p290@timeparser --create
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
grammar Timeparsing
|
2
|
+
rule root
|
3
|
+
(dot_seperated / hours / minutes)*
|
4
|
+
{
|
5
|
+
def value
|
6
|
+
self.elements.inject(0) {|akk, e| akk += e.value; akk }
|
7
|
+
end
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
rule dot_seperated
|
12
|
+
[0-9]* ':' [0-9]*
|
13
|
+
{
|
14
|
+
def value
|
15
|
+
elements[0].text_value.to_i*60 + elements[2].text_value.to_i
|
16
|
+
end
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
rule hours
|
21
|
+
([0-9]* 'h' / 'hours')
|
22
|
+
{
|
23
|
+
def value
|
24
|
+
self.text_value.to_i * 60
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
rule minutes
|
30
|
+
( [0-9]* "m" / "min" / "minutes" )
|
31
|
+
{
|
32
|
+
def value
|
33
|
+
self.text_value.to_i
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/timeparser.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "timeparser/version"
|
2
|
+
require 'polyglot'
|
3
|
+
require 'treetop'
|
4
|
+
Treetop.load File.join(File.dirname(__FILE__), 'timeparser/timeparsing.treetop')
|
5
|
+
|
6
|
+
module Timeparser
|
7
|
+
class Parser
|
8
|
+
def parser
|
9
|
+
@parser ||= TimeparsingParser.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(string)
|
13
|
+
parser.parse(string).value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Timeparser do
|
4
|
+
it "creates instance" do
|
5
|
+
Timeparser::Parser.new.should_not be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:parser){ Timeparser::Parser.new }
|
9
|
+
|
10
|
+
it "parses hours" do
|
11
|
+
parser.parse('1h').should eql 60
|
12
|
+
end
|
13
|
+
|
14
|
+
it "parses minutes" do
|
15
|
+
parser.parse('1m').should eql 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "parses hours and minutes" do
|
19
|
+
parser.parse('1h20m').should eql 80
|
20
|
+
end
|
21
|
+
|
22
|
+
it "parses dot notation" do
|
23
|
+
parser.parse('1:20').should eql 80
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/timeparser.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "timeparser/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "timeparser"
|
7
|
+
s.version = Timeparser::VERSION
|
8
|
+
s.authors = ["Marcel Scherf"]
|
9
|
+
s.email = ["marcel.scherf@epicteams.com"]
|
10
|
+
s.homepage = "http://github.com/the-architect/timeparser"
|
11
|
+
s.summary = %q{Parses time information from strings.}
|
12
|
+
s.description = %q{Parses time information from strings.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "timeparser"
|
15
|
+
|
16
|
+
s.add_runtime_dependency "treetop"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timeparser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marcel Scherf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: treetop
|
16
|
+
requirement: &70191347829680 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70191347829680
|
25
|
+
description: Parses time information from strings.
|
26
|
+
email:
|
27
|
+
- marcel.scherf@epicteams.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- .rvmrc
|
34
|
+
- Gemfile
|
35
|
+
- Rakefile
|
36
|
+
- lib/timeparser.rb
|
37
|
+
- lib/timeparser/timeparsing.treetop
|
38
|
+
- lib/timeparser/version.rb
|
39
|
+
- spec/lib/timeparser_spec.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- timeparser.gemspec
|
42
|
+
homepage: http://github.com/the-architect/timeparser
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: timeparser
|
62
|
+
rubygems_version: 1.8.10
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Parses time information from strings.
|
66
|
+
test_files:
|
67
|
+
- spec/lib/timeparser_spec.rb
|
68
|
+
- spec/spec_helper.rb
|