Class: Precheck::CopyrightDateRule

Inherits:
AbstractTextMatchRule show all
Defined in:
precheck/lib/precheck/rules/copyright_date_rule.rb

Constant Summary

Constants inherited from AbstractTextMatchRule

AbstractTextMatchRule::WORD_SEARCH_TYPES

Instance Attribute Summary

Attributes inherited from AbstractTextMatchRule

#lowercased_words_to_look_for

Attributes inherited from FastlaneCore::ConfigItem

#allow_shell_conversion, #code_gen_default_value, #code_gen_sensitive, #conflict_block, #conflicting_options, #default_value, #default_value_dynamic, #deprecated, #description, #display_in_shell, #env_name, #env_names, #key, #optional, #sensitive, #short_option, #skip_type_validation, #verify_block

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractTextMatchRule

#allowed_lowercased_words, #pass_if_empty?, #remove_safe_words, #word_search_type

Methods inherited from TextRule

#handle_item?

Methods inherited from Rule

#check_item, #customize_with_data, default_value, #friendly_name, #handle_item?, #initialize, #inspect, #item_field_supported?, #needs_customization?, #perform_check, #skip_item_not_meant_for_this_rule, #to_s

Methods inherited from FastlaneCore::ConfigItem

#auto_convert_value, #data_type, #deprecated_description, #doc_default_value, #ensure_array_type_passes_validation, #ensure_boolean_type_passes_validation, #ensure_generic_type_passes_validation, #fetch_env_value, #help_default_value, #initialize, #is_string, #string?, #to_s, #update_code_gen_default_value_if_able!, #valid?, #verify!

Constructor Details

This class inherits a constructor from Precheck::Rule

Class Method Details

.descriptionObject



17
18
19
# File 'precheck/lib/precheck/rules/copyright_date_rule.rb', line 17

def self.description
  "using a copyright year in the future, or missing a copyright year"
end

.env_nameObject



9
10
11
# File 'precheck/lib/precheck/rules/copyright_date_rule.rb', line 9

def self.env_name
  "RULE_COPYRIGHT_DATE"
end

.friendly_nameObject



13
14
15
# File 'precheck/lib/precheck/rules/copyright_date_rule.rb', line 13

def self.friendly_name
  "Incorrect, or missing copyright date"
end

.keyObject



5
6
7
# File 'precheck/lib/precheck/rules/copyright_date_rule.rb', line 5

def self.key
  :copyright_date
end

Instance Method Details



38
39
40
41
# File 'precheck/lib/precheck/rules/copyright_date_rule.rb', line 38

def copyright_year(text)
  match = text.to_s.match(/\b(?:19|20)\d{2}\b/)
  match && match[0].to_i
end

#rule_blockObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'precheck/lib/precheck/rules/copyright_date_rule.rb', line 25

def rule_block
  return lambda { |text|
    year = copyright_year(text)
    if year.nil?
      RuleReturn.new(validation_state: VALIDATION_STATES[:failed], failure_data: "missing copyright year")
    elsif year > DateTime.now.year
      RuleReturn.new(validation_state: VALIDATION_STATES[:failed], failure_data: "copyright year is in the future: #{year}")
    else
      RuleReturn.new(validation_state: VALIDATION_STATES[:passed])
    end
  }
end

#supported_fields_symbol_setObject



21
22
23
# File 'precheck/lib/precheck/rules/copyright_date_rule.rb', line 21

def supported_fields_symbol_set
  [:copyright].to_set
end