Class: Vindsl::DSL
- Inherits:
-
Object
- Object
- Vindsl::DSL
- Defined in:
- lib/vindsl/dsl.rb
Instance Attribute Summary collapse
-
#country ⇒ Object
Returns the value of attribute country.
-
#manufacturer ⇒ Object
Returns the value of attribute manufacturer.
-
#model_year ⇒ Object
Returns the value of attribute model_year.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ DSL
constructor
A new instance of DSL.
- #regexp ⇒ Object
- #wmi_regexp ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ DSL
Returns a new instance of DSL.
7 8 9 |
# File 'lib/vindsl/dsl.rb', line 7 def initialize yield self end |
Instance Attribute Details
#country ⇒ Object
Returns the value of attribute country.
6 7 8 |
# File 'lib/vindsl/dsl.rb', line 6 def country @country end |
#manufacturer ⇒ Object
Returns the value of attribute manufacturer.
6 7 8 |
# File 'lib/vindsl/dsl.rb', line 6 def manufacturer @manufacturer end |
#model_year ⇒ Object
Returns the value of attribute model_year.
6 7 8 |
# File 'lib/vindsl/dsl.rb', line 6 def model_year @model_year end |
Instance Method Details
#regexp ⇒ Object
11 12 13 |
# File 'lib/vindsl/dsl.rb', line 11 def regexp Regexp.new "^#{ wmi_regexp }[#{Alphabet::ALPHABET_WITH_NUMBERS.join}]{14}$" end |
#wmi_regexp ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vindsl/dsl.rb', line 15 def wmi_regexp country_prefixes = WMI.country_prefixes_for country manufacturer_prefixes = WMI.manufacturer_prefixes_for manufacturer prefix_pairs = country_prefixes.product manufacturer_prefixes ok_prefixes = prefix_pairs.select { |(c, m)| Regexp.new(c).match m} chunks = ok_prefixes.map do |(_c, pfx)| need_dots = 3 - pfx.length pfx + ('.' * need_dots) end "(#{chunks.join '|'})" end |