Class: Corraios::Delivery

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(correios_response, service_name, service_code) ⇒ Delivery

Returns a new instance of Delivery.



9
10
11
12
13
14
# File 'lib/corraios/delivery.rb', line 9

def initialize(correios_response, service_name, service_code)
  @name = service_name
  @code = service_code
  @amount_of_posts = 1
  parse_response(correios_response)
end

Instance Attribute Details

#amount_of_postsObject (readonly)

Returns the value of attribute amount_of_posts.



7
8
9
# File 'lib/corraios/delivery.rb', line 7

def amount_of_posts
  @amount_of_posts
end

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/corraios/delivery.rb', line 4

def code
  @code
end

#deadlineObject (readonly)

Returns the value of attribute deadline.



5
6
7
# File 'lib/corraios/delivery.rb', line 5

def deadline
  @deadline
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



5
6
7
# File 'lib/corraios/delivery.rb', line 5

def error_message
  @error_message
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/corraios/delivery.rb', line 4

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/corraios/delivery.rb', line 5

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
# File 'lib/corraios/delivery.rb', line 33

def ==(other)
  @code == other.code
end

#error?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/corraios/delivery.rb', line 16

def error?
  !!@error_message
end

#merge!(other) ⇒ Object

Raises:



24
25
26
27
28
29
30
31
# File 'lib/corraios/delivery.rb', line 24

def merge!(other)
  raise CorraiosError unless self == other
  if success? && other.success?
    merge_when_success!(other)
  else
    merge_when_error!(other)
  end
end

#success?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/corraios/delivery.rb', line 20

def success?
  !error?
end