class Swift::Boiler::TokenPatternValidator

Public Instance Methods

contains_unique_instace_of_type(tokens, type) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 33
def contains_unique_instace_of_type(tokens, type)
  instance_counter = 0
  tokens.each do |token|
    if token.type == type
      instance_counter += 1
    end
  end
  instance_counter == 1
end
is_first_token_help_option(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 47
def is_first_token_help_option(tokens) 
  tokens.count > 0 && is_help_token(tokens[0])
end
is_first_token_template_name_type(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 43
def is_first_token_template_name_type(tokens)
  tokens.count > 0 && is_template_name_token(tokens[0])
end
is_first_token_template_option(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 55
def is_first_token_template_option(tokens) 
  tokens.count > 0 && is_template_token(tokens[0])
end
is_help_pattern(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 29
def is_help_pattern(tokens)
    tokens.count == 1 && is_first_token_help_option(tokens)
end
is_help_token(token) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 63
def is_help_token(token)
  token.type == Token::OPTION && (token.content == '-h' || token.content == '--help')
end
is_template_name_pattern(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 22
def is_template_name_pattern(tokens)
  has_one_template_name = contains_unique_instace_of_type(tokens, Token::TEMPLATE_NAME)
  has_one_template_path = contains_unique_instace_of_type(tokens, Token::TEMPLATE_PATH)
  has_one_class_name = contains_unique_instace_of_type(tokens, Token::CLASS_NAME)
  !has_one_template_path && has_one_class_name && has_one_template_name && is_first_token_template_name_type(tokens)
end
is_template_name_token(token) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 59
def is_template_name_token(token) 
  token.type == Token::TEMPLATE_NAME
end
is_template_path_pattern(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 15
def is_template_path_pattern(tokens)
  has_one_template_name = contains_unique_instace_of_type(tokens, Token::TEMPLATE_NAME)
  has_one_template_path = contains_unique_instace_of_type(tokens, Token::TEMPLATE_PATH)
  has_one_class_name = contains_unique_instace_of_type(tokens, Token::CLASS_NAME)
  !has_one_template_name && has_one_template_path && has_one_class_name && is_first_token_template_option(tokens)
end
is_template_token(token) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 67
def is_template_token(token)
  token.type == Token::OPTION && (token.content == '-t' || token.content == '--template')
end
is_token_pattern_valid(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 11
def is_token_pattern_valid(tokens)
  is_help_pattern(tokens) || is_template_path_pattern(tokens) || is_template_name_pattern(tokens)
end
validate(tokens) click to toggle source
# File lib/swift/boiler/token_pattern_validator.rb, line 7
def validate(tokens)
  tokens.count > 0 && is_token_pattern_valid(tokens)
end