Class: Fable::InkList::InkListItem

Inherits:
Object
  • Object
show all
Defined in:
lib/fable/ink_list.rb

Overview

The underlying type for a list item in ink. It stores the original list definition name as well as the item name, but without the value of the item. When the value is stored, it’s stored in a Dictionary of InkListItem and an integer.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ InkListItem

Returns a new instance of InkListItem.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fable/ink_list.rb', line 16

def initialize(options)
  # Create an item from a dot-separated string of the form
  # `list_definition_name.list_item_name`
  if options.has_key?(:full_name)
    name_parts = options[:full_name].split(".")
    self.origin_name = name_parts[0]
    self.item_name = name_parts[1]
  else
    self.origin_name = options[:origin_name]
    self.item_name = options[:item_name]
  end
end

Instance Attribute Details

#item_nameObject

The main name of the item as defined in ink



14
15
16
# File 'lib/fable/ink_list.rb', line 14

def item_name
  @item_name
end

#origin_nameObject

The name of the list where the item was originally defined.



11
12
13
# File 'lib/fable/ink_list.rb', line 11

def origin_name
  @origin_name
end

Class Method Details

.NullObject



29
30
31
# File 'lib/fable/ink_list.rb', line 29

def self.Null
  return self.new(origin_name: nil, item_name: nil)
end

Instance Method Details

#equal?(other_object) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
# File 'lib/fable/ink_list.rb', line 45

def equal?(other_object)
  return false if !other_object.is_a?(InkListItem)

  return (
    other_object.item_name == self.item_name &&
    other_object.origin_name == self.origin_name
  )
end

#full_nameObject Also known as: to_s

Get the full dot-separated name of the item, in the form of ‘list_definition_name.list_item_name`



39
40
41
# File 'lib/fable/ink_list.rb', line 39

def full_name
  return "#{origin_name.nil? ? "?" : origin_name}.#{item_name}"
end

#null_item?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/fable/ink_list.rb', line 33

def null_item?
  origin_name.nil? && item_name.null?
end