Class: ABI::Param
- Inherits:
-
Object
- Object
- ABI::Param
- Defined in:
- lib/abiparser/param.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#internal_type ⇒ Object
readonly
Returns the value of attribute internal_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #decl ⇒ Object
- #doc ⇒ Object
-
#initialize(type, name = nil, internal_type: nil, components: nil) ⇒ Param
constructor
check - find a “better” name for internal_type use a keyword param - why? why not?.
- #sig ⇒ Object
Constructor Details
#initialize(type, name = nil, internal_type: nil, components: nil) ⇒ Param
check - find a “better” name for internal_type
use a keyword param - why? why not?
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/abiparser/param.rb', line 20 def initialize( type, name=nil, internal_type: nil, components: nil ) ## note: type goes first!!! @type = type ## note: convert empty string "" to nil - why? why not? @name = if name && name.empty? nil else name end @internal_type = if internal_type && internal_type.empty? nil else internal_type end @components = components end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
3 4 5 |
# File 'lib/abiparser/param.rb', line 3 def components @components end |
#internal_type ⇒ Object (readonly)
Returns the value of attribute internal_type.
3 4 5 |
# File 'lib/abiparser/param.rb', line 3 def internal_type @internal_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/abiparser/param.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/abiparser/param.rb', line 3 def type @type end |
Class Method Details
.parse(o) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/abiparser/param.rb', line 7 def self.parse( o ) type = o['type'] internal_type = o['internalType'] name = o['name'] components = o['components'] ? o['components'].map { |c| parse( c ) } : nil new( type, name, internal_type: internal_type, components: components ) end |
Instance Method Details
#decl ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/abiparser/param.rb', line 65 def decl buf = '' buf << "#{sig} " buf << (@name ? @name : '_') ## use inline comment - why? why not? if @internal_type && @internal_type != sig buf << " /* #{@internal_type} */" end buf end |
#doc ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/abiparser/param.rb', line 54 def doc buf = '' if @internal_type && @internal_type != sig buf << "#{@internal_type} " else buf << "#{sig} " end buf << (@name ? @name : '_') buf end |
#sig ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/abiparser/param.rb', line 39 def sig @sig ||= begin if @components ## replace tuple with (type,...) ## e.g. tuple[] becomes (type,...)[] etc. tuple = @components.map {|c| c.sig }.join(',') @type.sub( "tuple", "(#{tuple})" ) else "#{@type}" end end @sig end |