Class: Vindsl::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/vindsl/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ DSL

Returns a new instance of DSL.

Yields:

  • (_self)

Yield Parameters:

  • _self (Vindsl::DSL)

    the object that the method was called on



7
8
9
# File 'lib/vindsl/dsl.rb', line 7

def initialize
  yield self
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



6
7
8
# File 'lib/vindsl/dsl.rb', line 6

def country
  @country
end

#manufacturerObject

Returns the value of attribute manufacturer.



6
7
8
# File 'lib/vindsl/dsl.rb', line 6

def manufacturer
  @manufacturer
end

#model_yearObject

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

#regexpObject



11
12
13
# File 'lib/vindsl/dsl.rb', line 11

def regexp
  Regexp.new "^#{ wmi_regexp }[#{Alphabet::ALPHABET_WITH_NUMBERS.join}]{14}$"
end

#wmi_regexpObject



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