class EgovUtils::Fileuid
Constants
- AVAILABLE_ATTRIBUTES
- BC_SNIPPET
- COURT_AGEND_SNIPPET
- COURT_SENAT_SNIPPET
- DASH_SNIPPET
- REGISTER_SNIPPET
- SLASH_SNIPPET
- Snippet
- TYPES
- YEAR_SNIPPET
Public Class Methods
new(str_val, **options)
click to toggle source
# File lib/egov_utils/fileuid.rb, line 134 def initialize(str_val, **options) @options = options.stringify_keys @str_val = str_val parse_str!(str_val) if str_val.is_a?(String) end
Public Instance Methods
==(other)
click to toggle source
# File lib/egov_utils/fileuid.rb, line 118 def ==(other) other.is_a?(Fileuid) && AVAILABLE_ATTRIBUTES.all?{|a| self.public_send(a) == other.public_send(a) } end
as_json(**options)
click to toggle source
# File lib/egov_utils/fileuid.rb, line 159 def as_json(**options) invalid? ? nil : to_s end
determine_type(str_val)
click to toggle source
# File lib/egov_utils/fileuid.rb, line 152 def determine_type(str_val) TYPES.each do |k, type| return k if str_val =~ type.to_regex end nil end
invalid?()
click to toggle source
# File lib/egov_utils/fileuid.rb, line 130 def invalid? !type || @invalid end
parse_str!(str_val, type=self.type)
click to toggle source
# File lib/egov_utils/fileuid.rb, line 140 def parse_str!(str_val, type=self.type) type ||= determine_type(str_val) @type = type return if invalid? match_data = str_val.match(type_definition.to_regex) if match_data type_definition.snippet_names.each_with_index{|s_name, idx| self.send(s_name+'=', match_data[idx+1]) } else @invalid = true end end
to_s()
click to toggle source
# File lib/egov_utils/fileuid.rb, line 163 def to_s if invalid? @str_val.to_s else type_definition.file_uid_to_s(self) end end
type()
click to toggle source
# File lib/egov_utils/fileuid.rb, line 122 def type @type ||= @options['type'] end
type_definition()
click to toggle source
# File lib/egov_utils/fileuid.rb, line 126 def type_definition TYPES[type] end