Class: Grub::GemLine

Inherits:
Object
  • Object
show all
Defined in:
lib/grub/gem_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ GemLine

Returns a new instance of GemLine.



6
7
8
9
10
11
12
13
# File 'lib/grub/gem_line.rb', line 6

def initialize(*args)
  named_params = args.last.respond_to?(:[]) && args.last
  @name = (named_params && named_params[:name]) || args[0]
  @original_line = (named_params && named_params[:original_line]) || args[1]
  @location = (named_params && named_params[:location]) || args[2]
  @prev_line_comment = (named_params && named_params[:prev_line_comment]) || args[3]
  @options = (named_params && named_params[:options]) || named_params
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



4
5
6
# File 'lib/grub/gem_line.rb', line 4

def location
  @location
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/grub/gem_line.rb', line 4

def name
  @name
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/grub/gem_line.rb', line 4

def options
  @options
end

#original_lineObject

Returns the value of attribute original_line.



4
5
6
# File 'lib/grub/gem_line.rb', line 4

def original_line
  @original_line
end

#prev_line_commentObject

Returns the value of attribute prev_line_comment.



4
5
6
# File 'lib/grub/gem_line.rb', line 4

def prev_line_comment
  @prev_line_comment
end

#specObject

Returns the value of attribute spec.



4
5
6
# File 'lib/grub/gem_line.rb', line 4

def spec
  @spec
end

Instance Method Details

#commentObject



15
16
17
18
# File 'lib/grub/gem_line.rb', line 15

def comment
  leading_spaces = original_line[0..leading_spaces_count - 1] if leading_spaces_count > 0
  comment = "#{leading_spaces}# #{info}"
end

#infoObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/grub/gem_line.rb', line 20

def info
  output = if options[:website_only]
    website
  elsif options[:description_only]
    description
  else
    description_and_website
  end
  output << "\n"
end

#should_insert?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/grub/gem_line.rb', line 31

def should_insert?
  !info.strip.empty? && !already_added_comment && !existing_comment_option
end