Class: SugoiPrettyJSON::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(log, options) ⇒ Parser

Returns a new instance of Parser.



26
27
28
29
30
31
32
33
34
# File 'lib/sugoi_pretty_json.rb', line 26

def initialize(log, options)
  @log = log.strip
  if options[:user_agent]
    parse_user_agent(json_key: options[:user_agent])
  end
  @parsed_hash_members = []
  @parsed_string_members = []
  @assigned_option_only = options[:only] || []
end

Instance Method Details

#parseObject



36
37
38
39
40
41
42
43
# File 'lib/sugoi_pretty_json.rb', line 36

def parse
  json = SugoiJSON.new(@log)
  json.parse_user_agent!(@user_agent_member)
  json.parse_hash!(@parsed_hash_members)
  json.parse_string!(@parsed_string_members)
  json.slice_only_option!(build_option_only)
  json.to_hash
end

#parse_hash(json_key:) {|parsed_member| ... } ⇒ Object

Yields:

  • (parsed_member)


51
52
53
54
55
# File 'lib/sugoi_pretty_json.rb', line 51

def parse_hash(json_key: )
  parsed_member = ParsedMember.new(json_key)
  yield(parsed_member)
  @parsed_hash_members << parsed_member
end

#parse_string(json_key:) {|parsed_member| ... } ⇒ Object

Yields:

  • (parsed_member)


45
46
47
48
49
# File 'lib/sugoi_pretty_json.rb', line 45

def parse_string(json_key: )
  parsed_member = ParsedMember.new(json_key)
  yield(parsed_member)
  @parsed_string_members << parsed_member
end

#parse_user_agent(json_key:) {|parsed_member| ... } ⇒ Object

Yields:

  • (parsed_member)


57
58
59
60
61
62
# File 'lib/sugoi_pretty_json.rb', line 57

def parse_user_agent(json_key: )
  parsed_member = ParsedMember.new(json_key)
  yield(parsed_member) if block_given?
  parsed_member.name ||= 'user_agent'
  @user_agent_member = parsed_member
end