Class: Razor::CLI::Document

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/razor/cli/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, format_type) ⇒ Document

Returns a new instance of Document.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/razor/cli/document.rb', line 9

def initialize(doc, format_type)
  @type = :single
  if doc.is_a?(Hash)
    if doc['+spec'].is_a?(Array)
      @spec, remaining_navigation = doc['+spec']
    else
      @spec = doc['spec']
    end
    @command = doc['command']
    if doc.has_key?('items')
      @type = :list
      @items = doc['items']
    end
  end
  @items ||= Array[doc]
  @format_view = Razor::CLI::Views.find_formatting(@spec, format_type, remaining_navigation)

  # Untransformed and unordered for displaying nested views.
  @original_items = @items
  @items = hide_or_transform_elements!(items, format_view)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/razor/cli/document.rb', line 7

def command
  @command
end

#format_viewObject (readonly)

Returns the value of attribute format_view.



7
8
9
# File 'lib/razor/cli/document.rb', line 7

def format_view
  @format_view
end

#itemsObject (readonly)

Returns the value of attribute items.



7
8
9
# File 'lib/razor/cli/document.rb', line 7

def items
  @items
end

#original_itemsObject (readonly)

Returns the value of attribute original_items.



7
8
9
# File 'lib/razor/cli/document.rb', line 7

def original_items
  @original_items
end

#specObject (readonly)

Returns the value of attribute spec.



7
8
9
# File 'lib/razor/cli/document.rb', line 7

def spec
  @spec
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/razor/cli/document.rb', line 7

def type
  @type
end

Instance Method Details

#is_list?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/razor/cli/document.rb', line 31

def is_list?
  @type == :list
end