Class: ProMashTxt::Style

Inherits:
Brewser::Style show all
Defined in:
lib/brewser/engines/promash_txt.rb

Instance Method Summary collapse

Methods inherited from Brewser::Style

#as_json, json_create

Methods inherited from Brewser::Model

#as_beerxml, #as_brewson, auto_migrate_down!, auto_migrate_up!, auto_upgrade!, default_repository_name

Instance Method Details

#from_promash(array) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/brewser/engines/promash_txt.rb', line 121

def from_promash(array)
  if pointer = array.index("BJCP Style and Style Guidelines")
    self.style_guide = "BJCP"
  elsif pointer = array.index("AHA Style and Style Guidelines")
    self.style_guide = "AHA"
  else
    raise Error, "ProMashTxt engine: unable to find style guideline"
  end
  # Line @ pointer should look like this:
  # 06-B  American Pale Ales, American Amber Ale    
  match_data = /^(?<category_number>\d{2})-(?<style_letter>\w{1})\s*(?<category>(\w\s*)+)\,\s(?<name>(\w\s*)+)/.match(array[pointer+2])
  if match_data
    self.name = match_data[:name]
    self.category = match_data[:category]
    self.category_number = match_data[:category_number]
    self.style_letter = match_data[:style_letter]
  else
    raise Error, "ProMashTxt engine: Unable to extract style details"
  end
  return self
end