Class: Mitake::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mitake/parser.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Parse API response

Since:

  • 0.1.0

Constant Summary collapse

ID_MATCHER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

/\[(\d+)\]/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Parser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Parser.

Since:

  • 0.1.0



17
18
19
20
21
# File 'lib/mitake/parser.rb', line 17

def initialize(response)
  @response = response
  @body = response.body
  @items = []
end

Instance Attribute Details

#itemsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



13
14
15
# File 'lib/mitake/parser.rb', line 13

def items
  @items
end

Instance Method Details

#parseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: Improve response parser

Since:

  • 0.1.0



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mitake/parser.rb', line 27

def parse
  @body.each_line do |line|
    next new_item(Regexp.last_match(1)) if line =~ ID_MATCHER

    key, value = line.strip.split('=')
    next if key.nil?

    current[key] = value
  end
  @items << current
end