Class: Swift::Boiler::TokenFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/swift/boiler/token_factory.rb

Instance Method Summary collapse

Instance Method Details

#create_tokens_from_arguments(arguments) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/swift/boiler/token_factory.rb', line 7

def create_tokens_from_arguments(arguments)
  tokens = Array.new

  arguments.each do |argument|

    if is_valid_option(argument) 
      tokens << Token.new(Token::OPTION, argument)

    elsif is_valid_property(argument)
      tokens << Token.new(Token::PROPERTY, argument)

    elsif is_valid_template_name(argument)
      tokens << Token.new(Token::TEMPLATE_NAME, argument)

    elsif is_valid_template_path(argument)
      tokens << Token.new(Token::TEMPLATE_PATH, argument)

    elsif is_valid_class_name(argument)
      tokens << Token.new(Token::CLASS_NAME, argument)

    else
      raise ArgumentError.new("Argument was not recognized: #{argument}")
    end 
  end 

  tokens
end

#is_valid_class_name(argument) ⇒ Object



47
48
49
# File 'lib/swift/boiler/token_factory.rb', line 47

def is_valid_class_name(argument)
  argument =~ /\A[a-zA-Z][a-zA-Z\d_]+\z/
end

#is_valid_option(argument) ⇒ Object



35
36
37
# File 'lib/swift/boiler/token_factory.rb', line 35

def is_valid_option(argument)
  argument =~ /\A--[a-z]{3,}\z|\A-[a-z]\z/
end

#is_valid_property(argument) ⇒ Object



39
40
41
# File 'lib/swift/boiler/token_factory.rb', line 39

def is_valid_property(argument)
  argument =~ /\A[a-zA-Z_][a-zA-Z_\d\-]*:[a-zA-Z][a-zA-Z_.\d\-]{2,}\z/
end

#is_valid_template_name(argument) ⇒ Object



43
44
45
# File 'lib/swift/boiler/token_factory.rb', line 43

def is_valid_template_name(argument)
  ["controller", "c", "model", "m" "singleton", "s", "table_view_cell", "tableviewcell", "tvc", "view", "v", "viewmodel"].include?(argument)
end

#is_valid_template_path(argument) ⇒ Object



51
52
53
# File 'lib/swift/boiler/token_factory.rb', line 51

def is_valid_template_path(argument)
  argument =~ /\A[a-zA-Z\-.\/\\~\s_:]*[\/\\][\w\-\s]+.mustache\z|\A[\w\-\s]+.mustache\z/
end