Class: Swift::Boiler::TokenPatternValidator
- Inherits:
-
Object
- Object
- Swift::Boiler::TokenPatternValidator
- Defined in:
- lib/swift/boiler/token_pattern_validator.rb
Instance Method Summary collapse
- #contains_unique_instace_of_type(tokens, type) ⇒ Object
- #is_first_token_help_option(tokens) ⇒ Object
- #is_first_token_template_name_type(tokens) ⇒ Object
- #is_first_token_template_option(tokens) ⇒ Object
- #is_help_pattern(tokens) ⇒ Object
- #is_help_token(token) ⇒ Object
- #is_template_name_pattern(tokens) ⇒ Object
- #is_template_name_token(token) ⇒ Object
- #is_template_path_pattern(tokens) ⇒ Object
- #is_template_token(token) ⇒ Object
- #is_token_pattern_valid(tokens) ⇒ Object
- #validate(tokens) ⇒ Object
Instance Method Details
#contains_unique_instace_of_type(tokens, type) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
47 48 49 |
# 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) ⇒ Object
43 44 45 |
# 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) ⇒ Object
55 56 57 |
# 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) ⇒ Object
29 30 31 |
# 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) ⇒ Object
63 64 65 |
# 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) ⇒ Object
22 23 24 25 26 27 |
# 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) ⇒ Object
59 60 61 |
# 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) ⇒ Object
15 16 17 18 19 20 |
# 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) ⇒ Object
67 68 69 |
# 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) ⇒ Object
11 12 13 |
# 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) ⇒ Object
7 8 9 |
# File 'lib/swift/boiler/token_pattern_validator.rb', line 7 def validate(tokens) tokens.count > 0 && is_token_pattern_valid(tokens) end |