Module: Nerpin::Util

Defined in:
lib/nerpin/util.rb

Class Method Summary collapse

Class Method Details

.parse_spec_for_micronObject

ruby -rnerpin -rjson -e “puts JSON.pretty_generate(Nerpin::Util.parse_spec_for_micron)”



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nerpin/util.rb', line 7

def self.parse_spec_for_micron
  spec_url = 'http://ion-micron-miniak.wikia.com/wiki/Common_FAQ'
  doc      = Nokogiri::HTML(open(spec_url))
  table    = doc.xpath('//table').last

  table.xpath('tr').drop(1).inject({}) do |result, tr|
    id, key, min, max = tr.children.map do |el|
      el.text.strip
    end

    unless key.empty?
      key = key.downcase.
        gsub(/\-/, 'minus').
        gsub(/[\W]+/, '_').
        split('_').
        join('_').
        to_sym

      result[key] = {
        :id  => id.to_i,
        :min => min.to_i,
        :max => max.to_i
      }
    end

    result
  end
end