Class: Sirens::ObjectBrowserModel::InstanceVariable

Inherits:
Object
  • Object
show all
Defined in:
lib/sirens/models/object_browser_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, value:) ⇒ InstanceVariable

Returns a new instance of InstanceVariable.



90
91
92
93
# File 'lib/sirens/models/object_browser_model.rb', line 90

def initialize(key:, value:)
    @key = key
    @value = value
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



95
96
97
# File 'lib/sirens/models/object_browser_model.rb', line 95

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



95
96
97
# File 'lib/sirens/models/object_browser_model.rb', line 95

def value
  @value
end

Instance Method Details

#display_stringObject



101
102
103
104
105
# File 'lib/sirens/models/object_browser_model.rb', line 101

def display_string()
    return value_display_string if key.nil?

    "#{key_display_string} = #{value_display_string}"
end

#iconObject



97
98
99
# File 'lib/sirens/models/object_browser_model.rb', line 97

def icon()
    Icons.icon_for(@value)
end

#key_display_stringObject



107
108
109
110
111
112
113
# File 'lib/sirens/models/object_browser_model.rb', line 107

def key_display_string()
    if key.kind_of?(Numeric)
        "[#{key}]"
    else
        key.to_s
    end
end

#value_display_stringObject



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/sirens/models/object_browser_model.rb', line 115

def value_display_string()
    return "an Array(#{value.size})" if value.kind_of?(Array)
    return 'a Hash' if value.kind_of?(Hash)

    string = value.to_s

    if string.start_with?('#<')
        "a " + value.class.name
    else
        value.inspect
    end
end