Class: Pagseguro::Charge::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/charge/link.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLink

Returns a new instance of Link.



10
11
# File 'lib/pagseguro/charge/link.rb', line 10

def initialize
end

Instance Attribute Details

#hrefObject

Returns the value of attribute href.



4
5
6
# File 'lib/pagseguro/charge/link.rb', line 4

def href
  @href
end

#mediaObject

Returns the value of attribute media.



4
5
6
# File 'lib/pagseguro/charge/link.rb', line 4

def media
  @media
end

#relObject

Returns the value of attribute rel.



4
5
6
# File 'lib/pagseguro/charge/link.rb', line 4

def rel
  @rel
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/pagseguro/charge/link.rb', line 4

def type
  @type
end

Class Method Details

.fill_from_json(data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/pagseguro/charge/link.rb', line 19

def self.fill_from_json(data)
  return if data.nil?

  link = new
  link.rel = data["rel"]
  link.href = data["href"]
  link.media = data["media"]
  link.type = data["type"]
  link
end

Instance Method Details

#as_json(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/pagseguro/charge/link.rb', line 30

def as_json(options={})
  {
    rel: @rel,
    href: @href,
    media: @media,
    type: @type
  }
end

#image?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/pagseguro/charge/link.rb', line 43

def image?
  @media == 'application/image'
end

#json?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/pagseguro/charge/link.rb', line 47

def json?
  @media == 'application/json'
end

#pdf?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/pagseguro/charge/link.rb', line 39

def pdf?
  @media == 'application/pdf'
end

#to_json(*options) ⇒ Object



13
14
15
16
17
# File 'lib/pagseguro/charge/link.rb', line 13

def to_json(*options)
  hash = as_json(*options)
  hash.reject! {|k,v| v.nil?}
  hash.to_json(*options)
end