class RSpec::Hanami::FormParser

Public Instance Methods

call(html) click to toggle source
# File lib/rspec/hanami/form_parser.rb, line 6
def call(html)
  meta_list = select_inputs(html).map! { |input| input_data_hash(input) }
  meta_list.map! { |hash| ::Hanami::Utils::Hash.new(hash).symbolize! }
end

Private Instance Methods

input_data_hash(input) click to toggle source
# File lib/rspec/hanami/form_parser.rb, line 17
def input_data_hash(input)
  # trim all '<' and '>' chars. After that I add data
  # attr 'node' for first element (html tag name). And
  # in the end I split string on key-value pairs, trim '"'
  # and split key-value to key and value array.
  Hash[
    input
      .tr('<', '')
      .tr('>', '')
      .prepend('node=')
      .split(' ')
      .map! { |key_value| key_value.tr('"', '').split('=') }
  ]
end
select_inputs(html) click to toggle source
# File lib/rspec/hanami/form_parser.rb, line 13
def select_inputs(html)
  html.scan(/<input.+>|<textarea[^<]+>/)
end