Class: Tweezer::Gem

Inherits:
Object
  • Object
show all
Includes:
ASTHelper
Defined in:
lib/tweezer/gem.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ASTHelper

append_block_child, #blank_line, block?, block_children, group_block?, groups_from_group_block, s, source_block?, unparse_hash_node

Constructor Details

#initialize(node_or_name, version = nil, opts = {}) ⇒ Gem

Returns a new instance of Gem.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tweezer/gem.rb', line 5

def initialize(node_or_name, version = nil, opts = {})
  return init_from_node(node_or_name) if node_or_name.is_a?(
    Parser::AST::Node)

  @name = node_or_name

  if version.is_a? Hash
    @version = nil
    opts = version
  else
    @version = version
  end

  @groups = opts[:groups]
end

Instance Attribute Details

#groupsObject



41
42
43
# File 'lib/tweezer/gem.rb', line 41

def groups
  @groups ||= []
end

#nameObject (readonly)

Returns the value of attribute name.



38
39
40
# File 'lib/tweezer/gem.rb', line 38

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



38
39
40
# File 'lib/tweezer/gem.rb', line 38

def version
  @version
end

Class Method Details

.gem_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/tweezer/gem.rb', line 34

def self.gem_node?(node)
  node.children[1] == :gem
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
32
# File 'lib/tweezer/gem.rb', line 29

def ==(other)
  name == other.name &&
    version == other.version
end

#to_nodeObject



21
22
23
24
25
26
27
# File 'lib/tweezer/gem.rb', line 21

def to_node
  args = [nil, :gem, s(:str, name)]
  args << s(:str, version) if version
  args << s(:hash, groups_to_node) unless groups.empty?

  Parser::AST::Node.new(:send, args)
end