Class: SugoiPrettyJSON::SugoiJSON

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

Instance Method Summary collapse

Constructor Details

#initialize(log) ⇒ SugoiJSON

Returns a new instance of SugoiJSON.



11
12
13
14
15
16
17
18
19
20
# File 'lib/sugoi_pretty_json/sugoi_json.rb', line 11

def initialize(log)
  unless json?
    raise(JSON::ParserError, 'not json')
  end
  @json = JSON.parse(log)
  # 意味ある?
  # rescue JSON::ParserError
  #   puts '@@@@ done eval @@@@'
  #   JSON.parse(eval(@log).to_json)
end

Instance Method Details

#parse_hash!(parsed_members) ⇒ Object



37
38
39
# File 'lib/sugoi_pretty_json/sugoi_json.rb', line 37

def parse_hash!(parsed_members)
  parse(parsed_members, type: :hash)
end

#parse_string!(parsed_members) ⇒ Object



33
34
35
# File 'lib/sugoi_pretty_json/sugoi_json.rb', line 33

def parse_string!(parsed_members)
  parse(parsed_members, type: :string)
end

#parse_user_agent!(user_agent_member) ⇒ Object



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

def parse_user_agent!(user_agent_member)
  if user_agent_member
    @json[user_agent_member.name] =
      UserAgentParser.parse(@json[user_agent_member.json_key]).to_s
  end
end

#slice_only_option!(option_only) ⇒ Object



41
42
43
44
45
46
# File 'lib/sugoi_pretty_json/sugoi_json.rb', line 41

def slice_only_option!(option_only)
  return unless option_only
  @json.each do |key, value|
    @json.delete_if { |key, value| !option_only.include?(key) }
  end
end

#to_hashObject



22
23
24
# File 'lib/sugoi_pretty_json/sugoi_json.rb', line 22

def to_hash
  @json
end