shortee 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in shortee.gemspec
4
- gemspec
4
+ gemspec
data/lib/shortee.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "shortee/version"
2
2
  require "shortee/parser"
3
+ require "shortee/little_endian_parser"
3
4
 
4
5
  module Shortee
5
6
 
6
-
7
7
  end
8
8
 
9
9
 
@@ -0,0 +1,18 @@
1
+ require "parslet"
2
+
3
+ module Shortee
4
+
5
+ class Shortee::LittleEndianParser < Parslet::Parser
6
+
7
+ rule(:day) { match('[0-9]').repeat(1).as(:day) }
8
+ rule(:month) { match('[a-zA-Z0-9]').repeat(1).as(:month) }
9
+ rule(:year) { match('[0-9]').repeat(1).as(:year) }
10
+ rule(:forwardslash) { match['/'] }
11
+
12
+ rule(:date) { (day >> forwardslash >> month >> forwardslash >> year) }
13
+
14
+ root(:date)
15
+
16
+ end
17
+
18
+ end
@@ -3,71 +3,64 @@ require "parslet"
3
3
  module Shortee
4
4
 
5
5
  class Shortee::Parser < Parslet::Parser
6
+ def initialize(date_parser)
7
+ @date_parser = date_parser
8
+ end
6
9
 
7
- # A space and many spaces
10
+ # Generic rules
8
11
  rule(:space) { match('\s').repeat(1) }
9
12
  rule(:space?) { space.maybe }
10
-
11
- # Other rules
12
13
  rule(:dash?) { match['_-'].maybe }
14
+ rule(:colon) { match[':'] }
13
15
  rule(:at) { str('@') | (dash? >> (str('at') | str('AT')) >> dash?) }
14
16
  rule(:dot) { str('.') | (dash? >> (str('dot') | str('DOT')) >> dash?) }
15
-
16
- rule(:forwardslash) { match['/'] }
17
-
18
17
  rule(:integer) { match('[0-9]').repeat(1)>> space? }
19
- rule(:word) { match('[a-zA-Z0-9]').repeat(1).as(:word) >> space? }
20
- rule(:separator) { dot.as(:dot) >> space? | space }
21
- rule(:words) { word >> (separator >> word).repeat }
22
18
 
23
19
  # Shortee rules
24
20
  rule(:actor) { match('[a-zA-Z0-9]').repeat(1).as(:actor) >> space? }
25
21
  rule(:actee) { match('[a-zA-Z0-9]').repeat(1).as(:actee) >> space? }
26
22
  rule(:action) { match('[a-zA-Z]').repeat(1).as(:action) >> space? }
27
- rule(:amountnum) { match('[0-9.]').repeat(1).as(:amountnum) }
23
+ rule(:amountnum) { match('[0-9.]').repeat(1).as(:amountnum) >> space? }
28
24
  rule(:amountunits) { match('[a-zA-Z]').repeat(1).as(:amountunits) >> space? }
29
25
 
30
- rule(:day) { match('[0-9]').repeat(1).as(:day) }
31
- rule(:month) { match('[a-zA-Z]').repeat(1).as(:month) }
32
- rule(:year) { match('[0-9]').repeat(1).as(:year) }
33
- rule(:ukmonth) { match('[0-9]').repeat(1).as(:ukmonth) }
26
+ rule(:time) { match('[0-9:]').repeat(1).as(:time) >> space? }
27
+
28
+ # Date and time
29
+ rule(:date) { @date_parser }
34
30
 
35
- rule(:shorteeshort) {
31
+ rule(:short) {
36
32
  (space? >> at >> actor.as(:mainactor) >>
37
33
  action >>
38
34
  amountnum >> amountunits >>
39
- day >> forwardslash >>
40
- month >> forwardslash >> year).as(:shortee)
35
+ date >> space?).as(:short)
41
36
  }
42
37
 
43
- rule(:shorteeukshort) {
38
+ rule(:shortwithactee) {
44
39
  (space? >> at >> actor.as(:mainactor) >>
45
40
  action >>
41
+ at >> actee.as(:actee) >>
46
42
  amountnum >> amountunits >>
47
- day >> forwardslash >>
48
- ukmonth >> forwardslash >> year).as(:shortee)
43
+ date >> space?).as(:short)
49
44
  }
50
45
 
51
- rule(:shorteelong) {
46
+ rule(:shortwithtime) {
52
47
  (space? >> at >> actor.as(:mainactor) >>
53
48
  action >>
54
- at >> actee.as(:actee) >>
55
49
  amountnum >> amountunits >>
56
- day >> forwardslash >>
57
- month >> forwardslash >> year).as(:shortee)
50
+ time >> date >> space?).as(:short)
58
51
  }
59
52
 
60
- rule(:shorteeuklong) {
53
+ rule(:shortwithtimeandacteeg) {
61
54
  (space? >> at >> actor.as(:mainactor) >>
62
55
  action >>
63
56
  at >> actee.as(:actee) >>
64
57
  amountnum >> amountunits >>
65
- day >> forwardslash >>
66
- ukmonth >> forwardslash >> year).as(:shortee)
58
+ time >> date >> space?).as(:short)
67
59
  }
68
60
 
69
- rule(:allshorts) { shorteeshort | shorteeukshort | shorteelong | shorteeuklong }
61
+ rule(:allshorts) { short | shortwithactee | shortwithtime | shortwithtimeandacteeg }
70
62
 
71
63
  root(:allshorts)
72
64
  end
65
+
73
66
  end
@@ -1,3 +1,3 @@
1
1
  module Shortee
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+ require 'shortee'
4
+
5
+ describe Shortee::Parser do
6
+
7
+ it "parses a short with initial spaces" do
8
+ test_message =" @DateBoy tried 2things 01/sep/2013"
9
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
10
+ parsed_message = parser.parse(test_message)
11
+ parsed_message[:short][:mainactor][:actor].to_s.should eq("DateBoy")
12
+ end
13
+
14
+ it "parses a short with a trailing space" do
15
+ test_message ="@DateBoy tried 2things 01/sep/2013 "
16
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
17
+ parsed_message = parser.parse(test_message)
18
+ parsed_message[:short][:mainactor][:actor].to_s.should eq("DateBoy")
19
+ end
20
+
21
+ end
data/spec/parser_spec.rb CHANGED
@@ -4,73 +4,103 @@ require 'shortee'
4
4
 
5
5
  describe Shortee::Parser do
6
6
 
7
- it "should parse an actee" do
7
+ it "parses a short with time" do
8
+ test_message="@somebody did 1thing 08:00 01/jan/2012"
9
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
10
+ parsed_message = parser.parse(test_message)
11
+ parsed_message[:short][:time].to_s.should eq("08:00")
12
+ end
13
+
14
+ it "parses a short with time and actee" do
15
+ test_message="@somebody did @jimbo 1thing 09:00 01/jan/2012"
16
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
17
+ parsed_message = parser.parse(test_message)
18
+ parsed_message[:short][:time].to_s.should eq("09:00")
19
+ end
20
+
21
+ it "parses an actee" do
8
22
  test_message="@actor didto @actee 1something 01/12/2012"
9
- parser = Shortee::Parser.new
23
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
10
24
  parsed_message = parser.parse(test_message)
11
- parsed_message[:shortee][:actee][:actee].to_s.should eq("actee")
25
+ parsed_message[:short][:actee][:actee].to_s.should eq("actee")
12
26
  end
13
27
 
14
- it "should parse another actee" do
28
+ it "parses another actee" do
15
29
  test_message="@actor didto @jimboWilliams 1something 01/jan/2012"
16
- parser = Shortee::Parser.new
30
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
17
31
  parsed_message = parser.parse(test_message)
18
- parsed_message[:shortee][:actee][:actee].to_s.should eq("jimboWilliams")
32
+ parsed_message[:short][:actee][:actee].to_s.should eq("jimboWilliams")
19
33
  end
20
34
 
21
- it "should parse a valid actee" do
22
- test_message="@actor gave @frank 2cheeses 01/jan/2012"
23
- parser = Shortee::Parser.new
35
+ it "parses an action" do
36
+ test_message="@somebody did 1thing 01/jan/2012"
37
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
24
38
  parsed_message = parser.parse(test_message)
25
- parsed_message[:shortee][:actee][:actee].to_s.should eq("frank")
39
+ parsed_message[:short][:action].to_s.should eq("did")
26
40
  end
27
41
 
28
- it "should parse a valid mainactor" do
42
+ it "parses an amount" do
29
43
  test_message="@somebody did 1thing 01/jan/2012"
30
- parser = Shortee::Parser.new
44
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
31
45
  parsed_message = parser.parse(test_message)
32
- parsed_message[:shortee][:mainactor][:actor].to_s.should eq("somebody")
46
+ parsed_message[:short][:amountnum].should eq("1")
33
47
  end
34
48
 
35
- it "should parse a valid action" do
36
- test_message="@somebody did 1thing 01/jan/2012"
37
- parser = Shortee::Parser.new
49
+ it "parses a 1 decimal place amount" do
50
+ test_message="@somebody did 0.2things 01/jan/2012"
51
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
38
52
  parsed_message = parser.parse(test_message)
39
- parsed_message[:shortee][:action].to_s.should eq("did")
53
+ parsed_message[:short][:amountnum].should eq("0.2")
40
54
  end
41
55
 
42
- it "should parse a valid amount" do
43
- test_message="@somebody did 1thing 01/jan/2012"
44
- parser = Shortee::Parser.new
56
+ it "parses a unit" do
57
+ test_message="@somebody did 1jibberjabber 01/jan/2012"
58
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
59
+ parsed_message = parser.parse(test_message)
60
+ parsed_message[:short][:amountunits].should eq("jibberjabber")
61
+ end
62
+
63
+ it "parses a unit with a space before it and the amount" do
64
+ test_message="@somebody did 1 jibberjabber 01/jan/2012"
65
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
45
66
  parsed_message = parser.parse(test_message)
46
- parsed_message[:shortee][:amountnum].should eq("1")
67
+ parsed_message[:short][:amountunits].should eq("jibberjabber")
47
68
  end
48
69
 
49
- it "should parse a valid full date" do
70
+ it "parses a full standard uk date dd/mmm/yyyy" do
50
71
  test_message="@somebody did 1thing 01/jan/2012"
51
- parser = Shortee::Parser.new
72
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
52
73
  parsed_message = parser.parse(test_message)
53
- parsed_message[:shortee][:day].should eq("01")
54
- parsed_message[:shortee][:month].should eq("jan")
55
- parsed_message[:shortee][:year].should eq("2012")
74
+ parsed_message[:short][:day].should eq("01")
75
+ parsed_message[:short][:month].should eq("jan")
76
+ parsed_message[:short][:year].should eq("2012")
56
77
  end
57
78
 
58
- it "should parse a valid UK date" do
79
+ it "parses a UK numeric date" do
59
80
  test_message="@somebody did 1thing 01/12/2012"
60
- parser = Shortee::Parser.new
81
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
61
82
  parsed_message = parser.parse(test_message)
62
- parsed_message[:shortee][:day].should eq("01")
63
- parsed_message[:shortee][:ukmonth].should eq("12")
64
- parsed_message[:shortee][:year].should eq("2012")
83
+ parsed_message[:short][:day].should eq("01")
84
+ parsed_message[:short][:month].should eq("12")
85
+ parsed_message[:short][:year].should eq("2012")
65
86
  end
66
87
 
67
- it "should parse another valid UK date" do
88
+ it "parses another UK numeric date" do
68
89
  test_message="@frankee ate 2cheeses 13/01/2012"
69
- parser = Shortee::Parser.new
90
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
91
+ parsed_message = parser.parse(test_message)
92
+ parsed_message[:short][:day].should eq("13")
93
+ parsed_message[:short][:month].should eq("01")
94
+ parsed_message[:short][:year].should eq("2012")
95
+ end
96
+
97
+ it "parses another UK numeric date with actee" do
98
+ test_message="@bill won @theoscars 2awards 23/07/2015"
99
+ parser = Shortee::Parser.new(Shortee::LittleEndianParser.new)
70
100
  parsed_message = parser.parse(test_message)
71
- parsed_message[:shortee][:day].should eq("13")
72
- parsed_message[:shortee][:ukmonth].should eq("01")
73
- parsed_message[:shortee][:year].should eq("2012")
101
+ parsed_message[:short][:day].should eq("23")
102
+ parsed_message[:short][:month].should eq("07")
103
+ parsed_message[:short][:year].should eq("2015")
74
104
  end
75
105
 
76
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shortee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-12 00:00:00.000000000 Z
12
+ date: 2013-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -69,15 +69,16 @@ files:
69
69
  - .gitignore
70
70
  - .rspec
71
71
  - Gemfile
72
- - Guardfile
73
72
  - LICENSE.txt
74
73
  - README.md
75
74
  - Rakefile
76
75
  - Shortee_specification.md
77
76
  - lib/shortee.rb
77
+ - lib/shortee/little_endian_parser.rb
78
78
  - lib/shortee/parser.rb
79
79
  - lib/shortee/version.rb
80
80
  - shortee.gemspec
81
+ - spec/parser_spaces_spec.rb
81
82
  - spec/parser_spec.rb
82
83
  - spec/spec_helper.rb
83
84
  homepage: https://github.com/JeremyNevill/shortee
@@ -92,25 +93,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
93
  - - ! '>='
93
94
  - !ruby/object:Gem::Version
94
95
  version: '0'
95
- segments:
96
- - 0
97
- hash: 2187104680392310245
98
96
  required_rubygems_version: !ruby/object:Gem::Requirement
99
97
  none: false
100
98
  requirements:
101
99
  - - ! '>='
102
100
  - !ruby/object:Gem::Version
103
101
  version: '0'
104
- segments:
105
- - 0
106
- hash: 2187104680392310245
107
102
  requirements: []
108
103
  rubyforge_project:
109
- rubygems_version: 1.8.24
104
+ rubygems_version: 1.8.25
110
105
  signing_key:
111
106
  specification_version: 3
112
107
  summary: Shortee gem contains a message parser and specification for easy and fast
113
108
  event tracking using single line messages.
114
109
  test_files:
110
+ - spec/parser_spaces_spec.rb
115
111
  - spec/parser_spec.rb
116
112
  - spec/spec_helper.rb
data/Guardfile DELETED
@@ -1,112 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec' do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
-
9
- # Rails example
10
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
- watch('config/routes.rb') { "spec/routing" }
15
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
-
17
- # Capybara features specs
18
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
-
20
- # Turnip features and steps
21
- watch(%r{^spec/acceptance/(.+)\.feature$})
22
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
- end
24
-
25
-
26
- guard 'rspec' do
27
- watch(%r{^spec/.+_spec\.rb$})
28
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29
- watch('spec/spec_helper.rb') { "spec" }
30
-
31
- # Rails example
32
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
33
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
34
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
35
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
36
- watch('config/routes.rb') { "spec/routing" }
37
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
38
-
39
- # Capybara features specs
40
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
41
-
42
- # Turnip features and steps
43
- watch(%r{^spec/acceptance/(.+)\.feature$})
44
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
45
- end
46
-
47
-
48
- guard 'rspec' do
49
- watch(%r{^spec/.+_spec\.rb$})
50
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
51
- watch('spec/spec_helper.rb') { "spec" }
52
-
53
- # Rails example
54
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
55
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
56
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
57
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
58
- watch('config/routes.rb') { "spec/routing" }
59
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
60
-
61
- # Capybara features specs
62
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
63
-
64
- # Turnip features and steps
65
- watch(%r{^spec/acceptance/(.+)\.feature$})
66
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
67
- end
68
-
69
-
70
- guard 'rspec' do
71
- watch(%r{^spec/.+_spec\.rb$})
72
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
73
- watch('spec/spec_helper.rb') { "spec" }
74
-
75
- # Rails example
76
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
77
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
78
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
79
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
80
- watch('config/routes.rb') { "spec/routing" }
81
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
82
-
83
- # Capybara features specs
84
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
85
-
86
- # Turnip features and steps
87
- watch(%r{^spec/acceptance/(.+)\.feature$})
88
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
89
- end
90
-
91
-
92
- guard 'rspec' do
93
- watch(%r{^spec/.+_spec\.rb$})
94
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
95
- watch('spec/spec_helper.rb') { "spec" }
96
-
97
- # Rails example
98
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
99
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
100
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
101
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
102
- watch('config/routes.rb') { "spec/routing" }
103
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
104
-
105
- # Capybara features specs
106
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
107
-
108
- # Turnip features and steps
109
- watch(%r{^spec/acceptance/(.+)\.feature$})
110
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
111
- end
112
-