Class: SugoiPrettyJSON::Parser
- Inherits:
-
Object
- Object
- SugoiPrettyJSON::Parser
- Defined in:
- lib/sugoi_pretty_json.rb
Instance Method Summary collapse
-
#initialize(log, options) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #parse_hash(json_key:) {|parsed_member| ... } ⇒ Object
- #parse_string(json_key:) {|parsed_member| ... } ⇒ Object
- #parse_user_agent(json_key:) {|parsed_member| ... } ⇒ Object
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, ) @log = log.strip if [:user_agent] parse_user_agent(json_key: [:user_agent]) end @parsed_hash_members = [] @parsed_string_members = [] @assigned_option_only = [:only] || [] end |
Instance Method Details
#parse ⇒ Object
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
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
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
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 |