Class: HakumiComponents::Documentation::Node

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/hakumi_components/documentation/node.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Node

Returns a new instance of Node.



17
18
19
# File 'lib/hakumi_components/documentation/node.rb', line 17

def initialize(value)
  @value = T.let(value, T.untyped)
end

Class Method Details

.wrap(value) ⇒ Object



12
13
14
# File 'lib/hakumi_components/documentation/node.rb', line 12

def self.wrap(value)
  new(value)
end

Instance Method Details

#booleanObject



37
38
39
40
41
# File 'lib/hakumi_components/documentation/node.rb', line 37

def boolean
  return @value if @value == true || @value == false

  nil
end

#fetch(key) ⇒ Object



22
23
24
25
26
27
# File 'lib/hakumi_components/documentation/node.rb', line 22

def fetch(key)
  return self.class.wrap(nil) unless @value.is_a?(Hash)

  value = @value[key]
  self.class.wrap(value)
end

#object_arrayObject



62
63
64
65
66
67
68
69
70
# File 'lib/hakumi_components/documentation/node.rb', line 62

def object_array
  return [] unless @value.is_a?(Array)

  @value.filter_map do |entry|
    next unless entry.is_a?(Hash)

    self.class.wrap(entry)
  end
end

#scalar_to_stringObject



44
45
46
47
48
49
50
# File 'lib/hakumi_components/documentation/node.rb', line 44

def scalar_to_string
  return nil if @value.nil?
  return @value if @value.is_a?(String)
  return @value.to_s if @value.is_a?(Symbol) || @value.is_a?(Numeric) || @value == true || @value == false

  nil
end

#stringObject



30
31
32
33
34
# File 'lib/hakumi_components/documentation/node.rb', line 30

def string
  return @value if @value.is_a?(String)

  nil
end

#string_arrayObject



53
54
55
56
57
58
59
# File 'lib/hakumi_components/documentation/node.rb', line 53

def string_array
  return [] unless @value.is_a?(Array)

  @value.filter_map do |entry|
    entry if entry.is_a?(String)
  end
end