class Sip2::Responses::Base
Constants
- DATE_MATCH_REGEX
- LANGUAGE_LOOKUP_TABLE
- TIME_ZONE_LOOKUP_TABLE
Attributes
raw_response[R]
Public Class Methods
new(raw_response)
click to toggle source
# File lib/sip2/responses/base.rb, line 11 def initialize(raw_response) @raw_response = raw_response end
Protected Instance Methods
offset_from_zone(zone)
click to toggle source
# File lib/sip2/responses/base.rb, line 107 def offset_from_zone(zone) zone.strip! lookup = TIME_ZONE_LOOKUP_TABLE.find { |_, v| v.include? zone } lookup ? lookup.first : '+00:00' end
parse_datetime(position)
click to toggle source
# File lib/sip2/responses/base.rb, line 95 def parse_datetime(position) match = raw_response.match(/\A#{self.class::RESPONSE_ID}.{#{position}}#{DATE_MATCH_REGEX}/) return unless match _, year, month, day, zone, hour, minute, second = match.to_a Time.new( year.to_i, month.to_i, day.to_i, hour.to_i, minute.to_i, second.to_i, offset_from_zone(zone) ) end
parse_fixed_boolean(position)
click to toggle source
# File lib/sip2/responses/base.rb, line 83 def parse_fixed_boolean(position) parse_fixed_response(position) == 'Y' end
parse_fixed_response(position, count = 1)
click to toggle source
# File lib/sip2/responses/base.rb, line 79 def parse_fixed_response(position, count = 1) raw_response[/\A#{self.class::RESPONSE_ID}.{#{position}}(.{#{count}})/, 1] end
parse_optional_boolean(message_id)
click to toggle source
# File lib/sip2/responses/base.rb, line 87 def parse_optional_boolean(message_id) raw_response[/(?:\A.{#{self.class::FIXED_LENGTH_CHARS}}|\|)#{message_id}([YN])\|/, 1] == 'Y' end
parse_text(message_id)
click to toggle source
# File lib/sip2/responses/base.rb, line 91 def parse_text(message_id) raw_response[/(?:\A.{#{self.class::FIXED_LENGTH_CHARS}}|\|)#{message_id}(.*?)\|/, 1] end