Class: Aef::Hosts::Comment

Inherits:
Element
  • Object
show all
Defined in:
lib/aef/hosts/comment.rb

Overview

Represents a comment-only line as element of a hosts file

Instance Attribute Summary collapse

Attributes inherited from Element

#cache

Instance Method Summary collapse

Methods inherited from Element

#cache_filled?, #cache_string, #invalidate_cache!, #to_s

Constructor Details

#initialize(comment, options = {}) ⇒ Comment

Initializes a comment

Parameters:

  • comment (String)

    the comment

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :cache (String)

    sets a cached String representation

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
# File 'lib/aef/hosts/comment.rb', line 38

def initialize(comment, options = {})
  validate_options(options, :cache)
  
  raise ArgumentError, 'Comment cannot be empty' unless comment

  @comment = comment.to_s
  @cache   = options[:cache].to_s unless options[:cache].nil?
end

Instance Attribute Details

#commentString

The comment

Returns:

  • (String)


31
32
33
# File 'lib/aef/hosts/comment.rb', line 31

def comment
  @comment
end

Instance Method Details

#generate_string(options = {}) ⇒ String (protected)

Defines the algorithm to generate a String representation from scratch.

Returns:

  • (String)

    a generated String representation



66
67
68
# File 'lib/aef/hosts/comment.rb', line 66

def generate_string(options = {})
  "##{comment}\n"
end

#inspectString

A String representation for debugging purposes

Returns:

  • (String)


57
58
59
# File 'lib/aef/hosts/comment.rb', line 57

def inspect
  generate_inspect(self, :comment, :cache)
end