Class: CBOR::Box

Inherits:
Struct
  • Object
show all
Defined in:
lib/cbor-diag-support.rb

Direct Known Subclasses

Fbox, Ibox

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/cbor-diag-support.rb', line 2

def options
  @options
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



2
3
4
# File 'lib/cbor-diag-support.rb', line 2

def value
  @value
end

Class Method Details

.from_number(n, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cbor-diag-support.rb', line 9

def self.from_number(n, options={})
  case n
  when Box
    n.class.new(n.value, n.options.merge(options))
  when ::Integer
    Ibox.new(n, options.dup)
  when ::Float
    Fbox.new(n, options.dup)
  else
    raise ArgumentError, "cbor-diagnostic: can't box number from #{n.inspect}':\n"
  end
end

Instance Method Details

#cbor_diagnostic(opts = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/cbor-diag-support.rb', line 24

def cbor_diagnostic(opts = {})
  ret = value.cbor_diagnostic(opts)
  if ei = options[:ei]
    ret << "_#{ei}"
  end
  ret
end

#inspectObject



6
7
8
# File 'lib/cbor-diag-support.rb', line 6

def inspect
  "#<CBOR::Box #{self.class} value=#{value.inspect}, options=#{options.inspect}>"
end

#to_cborObject



21
22
23
# File 'lib/cbor-diag-support.rb', line 21

def to_cbor
  CBOR.encode(value)
end

#to_sObject



3
4
5
# File 'lib/cbor-diag-support.rb', line 3

def to_s
  value.to_s
end