reciter 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/reciter/parser.rb +11 -2
- data/lib/reciter/version.rb +1 -1
- metadata +21 -5
data/lib/reciter/parser.rb
CHANGED
@@ -21,6 +21,7 @@ module Reciter
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def unparse(*sequence)
|
24
|
+
mechanic, sequence = handle_unparse_params(sequence)
|
24
25
|
ranges = []
|
25
26
|
last = nil
|
26
27
|
sequence.sort.each do |n|
|
@@ -35,11 +36,11 @@ module Reciter
|
|
35
36
|
if r.end == r.begin || r.end == r.begin + 1
|
36
37
|
r.to_a
|
37
38
|
else
|
38
|
-
"%s
|
39
|
+
"%s%s%s" % [r.begin, mechanic ? '-' : " #{config.text_for_to} ", r.end]
|
39
40
|
end
|
40
41
|
}.
|
41
42
|
flatten.
|
42
|
-
join(', ')
|
43
|
+
join(mechanic ? ';' : ', ')
|
43
44
|
end
|
44
45
|
|
45
46
|
def self.config
|
@@ -48,6 +49,14 @@ module Reciter
|
|
48
49
|
|
49
50
|
private
|
50
51
|
|
52
|
+
def handle_unparse_params(params)
|
53
|
+
if params[0].is_a? Symbol
|
54
|
+
[params[0] == :mechanic, params[1..-1]]
|
55
|
+
else
|
56
|
+
[false, params]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
51
60
|
def validate_format(sequence)
|
52
61
|
subsequences = sequence.split(';')
|
53
62
|
raise InvalidInput unless !subsequences.empty? &&
|
data/lib/reciter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reciter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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: 2012-
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,16 +27,32 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 2.11.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pry
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: Parses number sequences.
|
31
47
|
email: rmanhaes@gmail.com
|
32
48
|
executables: []
|
33
49
|
extensions: []
|
34
50
|
extra_rdoc_files: []
|
35
51
|
files:
|
36
|
-
- lib/reciter/
|
52
|
+
- lib/reciter/error.rb
|
37
53
|
- lib/reciter/config.rb
|
54
|
+
- lib/reciter/parser.rb
|
38
55
|
- lib/reciter/version.rb
|
39
|
-
- lib/reciter/error.rb
|
40
56
|
- lib/reciter.rb
|
41
57
|
- README.rdoc
|
42
58
|
- LICENSE.txt
|
@@ -62,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
78
|
version: '0'
|
63
79
|
requirements: []
|
64
80
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.8.
|
81
|
+
rubygems_version: 1.8.23
|
66
82
|
signing_key:
|
67
83
|
specification_version: 3
|
68
84
|
summary: Parses number sequences
|