Class: Fields::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli/output/fields.rb

Direct Known Subclasses

Boolean, ContainerField, Date, Id, KeyValue, List, LongText, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Field

Returns a new instance of Field.



9
10
11
12
13
14
15
16
17
18
# File 'lib/hammer_cli/output/fields.rb', line 9

def initialize(options={})
  @hide_blank = options[:hide_blank].nil? ? false : options[:hide_blank]
  @hide_missing = options[:hide_missing].nil? ? true : options[:hide_missing]
  @path = options[:path] || []
  @label = options[:label]
  @sets = options[:sets]
  @replaced_by = options[:replaced_by]
  @deprecated = (options[:deprecated].nil?) ? !@replaced_by.nil? : options[:deprecated]
  @options = options
end

Instance Attribute Details

#deprecatedObject

Returns the value of attribute deprecated.



7
8
9
# File 'lib/hammer_cli/output/fields.rb', line 7

def deprecated
  @deprecated
end

#labelObject

Returns the value of attribute label.



7
8
9
# File 'lib/hammer_cli/output/fields.rb', line 7

def label
  @label
end

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/hammer_cli/output/fields.rb', line 7

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/hammer_cli/output/fields.rb', line 5

def path
  @path
end

#replaced_byObject

Returns the value of attribute replaced_by.



7
8
9
# File 'lib/hammer_cli/output/fields.rb', line 7

def replaced_by
  @replaced_by
end

#setsObject



41
42
43
# File 'lib/hammer_cli/output/fields.rb', line 41

def sets
  @sets || inherited_sets || default_sets
end

Instance Method Details

#display?(value) ⇒ Boolean

Returns:



45
46
47
48
49
50
51
52
53
# File 'lib/hammer_cli/output/fields.rb', line 45

def display?(value)
  if value.is_a?(HammerCLI::Output::DataMissing)
    !hide_missing?
  elsif value.nil?
    !hide_blank?
  else
    true
  end
end

#full_labelObject



36
37
38
39
# File 'lib/hammer_cli/output/fields.rb', line 36

def full_label
  return @label.to_s if @parent.nil?
  "#{@parent.full_label}/#{@label}"
end

#hide_blank?Boolean

Returns:



28
29
30
# File 'lib/hammer_cli/output/fields.rb', line 28

def hide_blank?
  @hide_blank
end

#hide_missing?Boolean

Returns:



32
33
34
# File 'lib/hammer_cli/output/fields.rb', line 32

def hide_missing?
  @hide_missing
end

#idObject



20
21
22
# File 'lib/hammer_cli/output/fields.rb', line 20

def id
  @options[:id] || @options[:key] || @label
end

#match_id?(field_id) ⇒ Boolean

Returns:



24
25
26
# File 'lib/hammer_cli/output/fields.rb', line 24

def match_id?(field_id)
  @options[:id] == field_id || @options[:key] == field_id || @label == _(field_id)
end

#parametersObject



55
56
57
# File 'lib/hammer_cli/output/fields.rb', line 55

def parameters
  @options
end