Class: PackTemplate::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/packtemplate/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.


9
10
11
# File 'lib/packtemplate/builder.rb', line 9

def initialize
  @result = ''
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result


7
8
9
# File 'lib/packtemplate/builder.rb', line 7

def result
  @result
end

Instance Method Details

#length_for(length) ⇒ Object (private)

Parameters:

  • length (Integer, :infinite, nil)

32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/packtemplate/builder.rb', line 32

def length_for(length)
  if length.respond_to? :to_sym
    length = length.to_sym
  end

  case length
  when Integer, :infinite
    length
  when nil
    :infinite
  else
    raise ArgumentError
  end
end

#origin_for(aliased) ⇒ Object (private)

Parameters:

  • aliased (Symbol)

27
28
29
# File 'lib/packtemplate/builder.rb', line 27

def origin_for(aliased)
  ALIASES.fetch aliased
end

#suffix_for(length) ⇒ Object (private)

Parameters:

  • length (Integer, :infinite, nil)

48
49
50
# File 'lib/packtemplate/builder.rb', line 48

def suffix_for(length)
  length == :infinite ? :'*' : length
end

#template_for(aliased, length) ⇒ String (private)

Parameters:

  • aliased (Symbol, String, #to_sym)
  • length (Integer, :infinite, nil)

Returns:

  • (String)

18
19
20
21
22
23
24
# File 'lib/packtemplate/builder.rb', line 18

def template_for(aliased, length)
  length = length_for length
  suffix = suffix_for length
  origin = origin_for aliased.to_sym

  "#{origin}#{suffix}"
end