eagle_labels 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
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eagle_labels.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # EagleLabels
2
+
3
+ OO Eagle Lables
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'eagle_labels'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install eagle_labels
18
+
19
+ ## Usage
20
+
21
+ ### Categories definition
22
+
23
+ adjective:
24
+ code: A
25
+ features:
26
+ type:
27
+ qualifying: Q
28
+ grade:
29
+ appreciative: A
30
+ gender:
31
+ male: M
32
+ female: F
33
+ common: C
34
+ number:
35
+ singular: S
36
+ plural: P
37
+ invariably: N
38
+ case:
39
+ function:
40
+ participle: P
41
+
42
+ ### Initialization
43
+
44
+ EagleLabels::Specification.new # with default categories
45
+ #or
46
+ EagleLabels::Specification.new 'categories.yml'
47
+ #or
48
+ EagleLabels::Specification.new category: {'code' => 'C', 'features' => {'feature' => {'value1' => 1, 'value2' => 2}}}
49
+
50
+ ### Examples
51
+
52
+ spec = EagleLabels::Specification.new
53
+
54
+ spec.all_labels
55
+ spec.valid_label? 'AQMSP'
56
+ spec.starts_with 'AQ'
57
+ spec.names_of 'AQMSP'
58
+ spec.next_codes 'AQ'
59
+ spec.tails 'AQ'
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,186 @@
1
+ adjective:
2
+ code: A
3
+ features:
4
+ type:
5
+ qualifying: Q
6
+ grade:
7
+ appreciative: A
8
+ gender:
9
+ male: M
10
+ female: F
11
+ common: C
12
+ number:
13
+ singular: S
14
+ plural: P
15
+ invariably: N
16
+ case:
17
+ function:
18
+ participle: P
19
+ adverb:
20
+ code: R
21
+ features:
22
+ type:
23
+ general: G
24
+ article:
25
+ code: T
26
+ features:
27
+ type:
28
+ defined: D
29
+ gender:
30
+ male: M
31
+ female: F
32
+ common: C
33
+ number:
34
+ sigular: S
35
+ plural: P
36
+ case:
37
+ determinant:
38
+ code: D
39
+ features:
40
+ type:
41
+ demonstrative: D
42
+ possessive: P
43
+ interrogative: T
44
+ exclamation: E
45
+ undefined: I
46
+ person:
47
+ first: 1
48
+ second: 2
49
+ third: 3
50
+ gender:
51
+ male: M
52
+ female: F
53
+ common: C
54
+ number:
55
+ sigular: S
56
+ plural: P
57
+ case:
58
+ holder:
59
+ first_singular: 1
60
+ second_singular: 2
61
+ third: 0
62
+ first_plural: 4
63
+ first_plural: 5
64
+ name:
65
+ code: N
66
+ features:
67
+ type:
68
+ common: C
69
+ own: P
70
+ gender:
71
+ male: M
72
+ female: F
73
+ common: C
74
+ number:
75
+ sigular: S
76
+ plural: P
77
+ case:
78
+ semantic_gender:
79
+ grade:
80
+ sppreciative: A
81
+ word:
82
+ code: V
83
+ features:
84
+ type:
85
+ home: M
86
+ assistant: A
87
+ mode:
88
+ callsign: I
89
+ subjunctive: S
90
+ imperative: M
91
+ conditional: C
92
+ infinitive: N
93
+ gerund: G
94
+ participle: P
95
+ time:
96
+ present: P
97
+ imperfect: I
98
+ future: F
99
+ past: S
100
+ person:
101
+ first: 1
102
+ second: 2
103
+ third: 3
104
+ number:
105
+ sigular: S
106
+ plural: P
107
+ gender:
108
+ male: M
109
+ female: F
110
+ common: C
111
+ pronoun:
112
+ code: P
113
+ features:
114
+ type:
115
+ personal: P
116
+ demonstrative: D
117
+ possessive: X
118
+ undefined: I
119
+ interrogative: T
120
+ relative: R
121
+ person:
122
+ first: 1
123
+ second: 2
124
+ third: 3
125
+ gender:
126
+ male: M
127
+ female: F
128
+ common: C
129
+ number:
130
+ sigular: S
131
+ plural: P
132
+ case:
133
+ nominative: N
134
+ accusative: A
135
+ dative: D
136
+ oblique: O
137
+ holder:
138
+ first_singular: 1
139
+ first_singular: 2
140
+ third: 0
141
+ first_plural: 4
142
+ first_plural: 5
143
+ politeness:
144
+ polite: P
145
+ conjunction:
146
+ code: C
147
+ features:
148
+ type:
149
+ coordinated: C
150
+ subordinate: S
151
+ numeral:
152
+ code: M
153
+ features:
154
+ type:
155
+ cardinal: C
156
+ ordinal: O
157
+ gender:
158
+ male: M
159
+ female: F
160
+ common: C
161
+ number:
162
+ sigular: S
163
+ plural: P
164
+ case:
165
+ function:
166
+ pronoun: P
167
+ determinant: D
168
+ adjective: A
169
+ interjection:
170
+ code: R
171
+ abbreviation:
172
+ code: Y
173
+ preposition:
174
+ code: S
175
+ features:
176
+ type:
177
+ preposition: P
178
+ form:
179
+ simple: S
180
+ contracted: C
181
+ gender:
182
+ male: M
183
+ number:
184
+ sigular: S
185
+ punctuation_sign:
186
+ code: F
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/eagle_labels/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'eagle_labels'
6
+ s.version = EagleLabels::VERSION
7
+ s.authors = ["Damián D'Onia", "Gabriel Naiman"]
8
+ s.email = ['ddonia@gmail.com', 'gnaiman@gmail.com']
9
+ s.homepage = 'https://github.com/ddonia/eagle_labels'
10
+ s.description = 'OO Eagle Lables'
11
+ s.summary = 'OO Eagle Lables'
12
+
13
+ s.files = `git ls-files`.split($\)
14
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_development_dependency 'rspec'
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'yaml'
2
+
3
+ require "eagle_labels/version"
4
+ require "eagle_labels/specification"
5
+ require "eagle_labels/category"
6
+ require "eagle_labels/feature"
7
+ require "eagle_labels/value"
@@ -0,0 +1,22 @@
1
+ module EagleLabels
2
+ class Category
3
+ attr_reader :name, :code
4
+
5
+ def initialize(name, spec)
6
+ @name = name
7
+ @code = spec['code'].to_s
8
+ @features = spec['features'] || {}
9
+ end
10
+
11
+ def features
12
+ @features.map { |k, v| Feature.new(k, v) }
13
+ end
14
+
15
+ def all_labels
16
+ features.inject([]) do |labels, feature|
17
+ labels.any? ? labels.product(feature.codes) : feature.codes
18
+ end.map { |l| "#{code}#{l.is_a?(String) ? l : l.flatten.join}" }
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module EagleLabels
2
+ class Feature
3
+ attr_reader :name
4
+
5
+ def initialize(name, spec)
6
+ @name = name
7
+ @values = spec || {}
8
+ end
9
+
10
+ def values
11
+ @values.map { |k, v| Value.new(k, v) }
12
+ end
13
+
14
+ def codes
15
+ values.map(&:code) | ['0']
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ module EagleLabels
2
+ class Specification
3
+
4
+ def initialize(spec=nil)
5
+ if spec.is_a? Hash
6
+ @spec = spec
7
+ elsif spec.is_a?(String) && File.exist?(spec)
8
+ @spec = YAML.load_file(spec)
9
+ else
10
+ @spec = YAML.load_file("#{File.dirname(__FILE__)}/../../config/default_categories.yml")
11
+ end
12
+ end
13
+
14
+ def categories
15
+ @spec.map { |k, v| Category.new(k, v) }
16
+ end
17
+
18
+ def all_labels
19
+ categories.map(&:all_labels).flatten
20
+ end
21
+
22
+ def starts_with(prefix)
23
+ if prefix.size == 0
24
+ labels = all_labels
25
+ else
26
+ category = categories.detect { |c| c.code == prefix[0] }
27
+ labels = category.all_labels
28
+ end
29
+ labels.select { |l| l.match("^#{prefix}") }
30
+ end
31
+
32
+ def tails(prefix)
33
+ starts_with(prefix).map { |l| l.sub prefix, '' }
34
+ end
35
+
36
+ def next_codes(prefix)
37
+ if prefix.size == 0
38
+ categories.map(&:code)
39
+ else
40
+ category = categories.detect { |c| c.code == prefix[0] }
41
+ category.features.size > prefix.size-1 ? category.features[prefix.size-1].codes : []
42
+ end
43
+ end
44
+
45
+ def valid_label?(label)
46
+ all_labels.include? label
47
+ end
48
+
49
+ def names_of(label)
50
+ return [] unless valid_label? label
51
+
52
+ codes = label.chars.to_a
53
+ category_code = codes.shift
54
+ category = categories.detect { |c| c.code == category_code }
55
+ names = [category.name]
56
+
57
+ category.features.each do |feature|
58
+ feature_code = codes.shift
59
+ if value = feature.values.detect { |v| v.code == feature_code }
60
+ names << value.name
61
+ end
62
+ end
63
+
64
+ names
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ module EagleLabels
2
+ class Value
3
+ attr_reader :name, :code
4
+
5
+ def initialize(name, code)
6
+ @name = name
7
+ @code = code.to_s
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module EagleLabels
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Category do
4
+
5
+ it 'List all values' do
6
+ spec = Specification.new 'dummy_spec.yml'
7
+
8
+ spec.categories.first.all_labels.should eq %w(1A1 1A2 1A3 1A0 1B1 1B2 1B3 1B0 1C1 1C2 1C3 1C0 101 102 103 100)
9
+ end
10
+
11
+ end
@@ -0,0 +1,35 @@
1
+ category_1:
2
+ code: 1
3
+ features:
4
+ letter:
5
+ value_a: A
6
+ value_b: B
7
+ value_c: C
8
+ number:
9
+ value_1: 1
10
+ value_2: 2
11
+ value_3: 3
12
+
13
+ category_2:
14
+ code: 2
15
+ features:
16
+ letter:
17
+ value_a: A
18
+ value_b: B
19
+ value_c: C
20
+ number:
21
+ value_1: 1
22
+ value_2: 2
23
+ value_3: 3
24
+
25
+ category_3:
26
+ code: 3
27
+ features:
28
+ letter:
29
+ value_a: A
30
+ value_b: B
31
+ value_c: C
32
+ number:
33
+ value_1: 1
34
+ value_2: 2
35
+ value_3: 3
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe EagleLabels, '-> Initializations' do
4
+
5
+ it 'Initialize from hash' do
6
+ spec = Specification.new category: {'code' => 'C', 'features' => {'feature' => {'value1' => 1, 'value2' => 2}}}
7
+
8
+ spec.should have(1).categories
9
+ spec.categories.first.name.should eq :category
10
+ spec.categories.first.code.should eq 'C'
11
+ spec.categories.first.should have(1).features
12
+ spec.categories.first.features.first.name.should eq 'feature'
13
+ spec.categories.first.features.first.codes.should eq %w(1 2 0)
14
+ end
15
+
16
+ it 'Initialize from yml file' do
17
+ spec = Specification.new 'dummy_spec.yml'
18
+
19
+ spec.should have(3).categories
20
+ spec.categories.map(&:name).should eq %w(category_1 category_2 category_3)
21
+ spec.categories.map(&:code).should eq %w(1 2 3)
22
+
23
+ spec.categories.each do |category|
24
+ category.should have(2).features
25
+ category.features.map(&:name).should eq %w(letter number)
26
+
27
+ category.features[0].values[0].name.should eq 'value_a'
28
+ category.features[0].values[0].code.should eq 'A'
29
+ category.features[0].values[1].name.should eq 'value_b'
30
+ category.features[0].values[1].code.should eq 'B'
31
+ category.features[0].values[2].name.should eq 'value_c'
32
+ category.features[0].values[2].code.should eq 'C'
33
+
34
+ category.features[1].values[0].name.should eq 'value_1'
35
+ category.features[1].values[0].code.should eq '1'
36
+ category.features[1].values[1].name.should eq 'value_2'
37
+ category.features[1].values[1].code.should eq '2'
38
+ category.features[1].values[2].name.should eq 'value_3'
39
+ category.features[1].values[2].code.should eq '3'
40
+ end
41
+ end
42
+
43
+ it 'Initialize with default configuration' do
44
+ spec = Specification.new
45
+
46
+ spec.should have(13).categories
47
+ end
48
+
49
+ end
@@ -0,0 +1,3 @@
1
+ require 'eagle_labels'
2
+
3
+ include EagleLabels
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Specification do
4
+
5
+ let(:spec) { Specification.new 'dummy_spec.yml' }
6
+
7
+ it 'List all labels' do
8
+ combination = %w(A1 A2 A3 A0 B1 B2 B3 B0 C1 C2 C3 C0 01 02 03 00)
9
+
10
+ all_labels = spec.categories.inject([]) do |labels, category|
11
+ labels << combination.map { |c| "#{category.code}#{c}" }
12
+ end.flatten
13
+
14
+ spec.all_labels.should eq all_labels
15
+ end
16
+
17
+ it 'List labels with empty prefix' do
18
+ list = spec.starts_with ''
19
+
20
+ list.should eq spec.all_labels
21
+ end
22
+
23
+ it 'List labels with category prefix' do
24
+ list = spec.starts_with '1'
25
+
26
+ list.should eq %w(1A1 1A2 1A3 1A0 1B1 1B2 1B3 1B0 1C1 1C2 1C3 1C0 101 102 103 100)
27
+ end
28
+
29
+ it 'List labels with feature prefix' do
30
+ list = spec.starts_with '1A'
31
+
32
+ list.should eq %w(1A1 1A2 1A3 1A0)
33
+ end
34
+
35
+ it 'List tails from prefix' do
36
+ list = spec.tails '1A'
37
+
38
+ list.should eq %w(1 2 3 0)
39
+ end
40
+
41
+ it 'List next codes from prefix' do
42
+ list = spec.next_codes '1A'
43
+
44
+ list.should eq %w(1 2 3 0)
45
+ end
46
+
47
+ it 'Validate label' do
48
+ spec.valid_label?('XXX').should be_false
49
+ spec.valid_label?('1A1').should be_true
50
+ end
51
+
52
+ it 'Convert label to names' do
53
+ list = spec.names_of '1A1'
54
+
55
+ list.should eq %w(category_1 value_a value_1)
56
+ end
57
+
58
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eagle_labels
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Damián D'Onia
9
+ - Gabriel Naiman
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-22 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &22386000 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *22386000
26
+ description: OO Eagle Lables
27
+ email:
28
+ - ddonia@gmail.com
29
+ - gnaiman@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - config/default_categories.yml
40
+ - eagle_labels.gemspec
41
+ - lib/eagle_labels.rb
42
+ - lib/eagle_labels/category.rb
43
+ - lib/eagle_labels/feature.rb
44
+ - lib/eagle_labels/specification.rb
45
+ - lib/eagle_labels/value.rb
46
+ - lib/eagle_labels/version.rb
47
+ - spec/category_spec.rb
48
+ - spec/dummy_spec.yml
49
+ - spec/initializations_spec.rb
50
+ - spec/spec_helper.rb
51
+ - spec/specification_spec.rb
52
+ homepage: https://github.com/ddonia/eagle_labels
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.16
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: OO Eagle Lables
76
+ test_files:
77
+ - spec/category_spec.rb
78
+ - spec/dummy_spec.yml
79
+ - spec/initializations_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/specification_spec.rb