Class: Lib::TL1::Huawei::Message::Output

Inherits:
Message::Output
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lib/tl1/huawei/message/output.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, sid: nil, date: nil, time: nil, ctag: nil, cc: nil, text_block: nil) ⇒ Output

Returns a new instance of Output.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lib/tl1/huawei/message/output.rb', line 17

def initialize(message = nil, sid: nil, date: nil, time: nil, ctag: nil, cc: nil, text_block: nil)
  if message.nil?
    super sid: sid, date: date, time: time, ctag: ctag, cc: cc, text_block: text_block
  else
    message = Lib::TL1::Message.parse message
    unless message.instance_of? Lib::TL1::Message::Output
      raise ArgumentError, "No implicit conversion form #{message.class.name} to #{self.class.name}"
    end

    super(
      sid: message.sid,
      date: message.date,
      time: message.time,
      ctag: message.ctag,
      cc: message.cc,
      text_block: message.text_block
    )
  end
  raise Lib::TL1::Huawei::StandardError.new(self.endesc, self.error_number) unless self.error_number.to_i == 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)



116
117
118
119
120
121
122
123
# File 'lib/lib/tl1/huawei/message/output.rb', line 116

def method_missing(method_name, *args)
  super if (blktotal.to_i > 1) || en.to_i.positive?
  if response.first.respond_to? method_name
    response.first.send method_name
  else
    super
  end
end

Class Method Details

.parse(message) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/lib/tl1/huawei/message/output.rb', line 98

def self.parse(message)
  message = Lib::TL1::Message.parse message
  unless message.instance_of? Lib::TL1::Message::Output
    raise ArgumentError, "No implicit conversion of #{message.class.name} to #{self.class.name}"
  end

  new(
    sid: message.sid,
    date: message.date,
    time: message.time,
    ctag: message.ctag,
    cc: message.cc,
    text_block: message.text_block
  )
end

Instance Method Details

#blkcountObject



76
77
78
79
# File 'lib/lib/tl1/huawei/message/output.rb', line 76

def blkcount
  parse_quoted_line unless defined? @blkcount
  @blkcount
end

#blktagObject



71
72
73
74
# File 'lib/lib/tl1/huawei/message/output.rb', line 71

def blktag
  parse_text_block unless defined? @blktag
  @blktag
end

#blktotalObject



81
82
83
84
# File 'lib/lib/tl1/huawei/message/output.rb', line 81

def blktotal
  parse_quoted_line unless defined? @blktotal
  @blktotal
end

#enObject Also known as: error_code, return_code, error_number



57
58
59
60
# File 'lib/lib/tl1/huawei/message/output.rb', line 57

def en
  parse_text_block unless defined? @en
  @en
end

#endescObject



66
67
68
69
# File 'lib/lib/tl1/huawei/message/output.rb', line 66

def endesc
  parse_text_block unless defined? @endesc
  @endesc
end

#responseObject Also known as: response_message



91
92
93
94
# File 'lib/lib/tl1/huawei/message/output.rb', line 91

def response
  parse_result unless defined? @response
  @response
end

#titleObject



86
87
88
89
# File 'lib/lib/tl1/huawei/message/output.rb', line 86

def title
  parse_result unless defined? @title
  @title
end

#to_hObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/lib/tl1/huawei/message/output.rb', line 38

def to_h
  {
    sid: self.sid.to_s,
    date: self.date.to_s,
    time: self.time.to_s,
    ctag: self.ctag.to_s,
    cc: self.cc.to_s,
    en: self.en,
    endesc: self.endesc,
    blktag: self.blktag,
    blkcount: self.blkcount,
    blktotal: self.blktotal,
    title: self.title,
    response: self.response.map(&:to_h).map do |r|
      r.transform_values { |v| v.force_encoding('iso-8859-1').encode('utf-8') }
    end
  }
end