Class: EgovUtils::Fileuid::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/egov_utils/fileuid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*attrs) ⇒ Type

Returns a new instance of Type.



52
53
54
# File 'lib/egov_utils/fileuid.rb', line 52

def initialize(*attrs)
  @snippets = attrs
end

Instance Attribute Details

#snippetsObject (readonly)

Returns the value of attribute snippets.



50
51
52
# File 'lib/egov_utils/fileuid.rb', line 50

def snippets
  @snippets
end

Instance Method Details

#file_uid_to_s(fileuid) ⇒ Object



72
73
74
# File 'lib/egov_utils/fileuid.rb', line 72

def file_uid_to_s(fileuid)
  snippets.collect{|snippet| snippet.static? ? snippet.name : fileuid.public_send(snippet.name) }.join
end

#snippet_namesObject



56
57
58
# File 'lib/egov_utils/fileuid.rb', line 56

def snippet_names
  snippets.select{|s| !s.static? }.collect{|s| s.name}
end

#to_regexObject



68
69
70
# File 'lib/egov_utils/fileuid.rb', line 68

def to_regex
  /\A#{to_regex_s}\z/
end

#to_regex_sObject



64
65
66
# File 'lib/egov_utils/fileuid.rb', line 64

def to_regex_s
  snippets.collect{|s| (s.type == :static ? s.to_regex_s : "(#{s.to_regex_s})") }.join()
end

#validate!Object



60
61
62
# File 'lib/egov_utils/fileuid.rb', line 60

def validate!
  raise "Snippet names for file uid type has to be uniq!" unless snippet_names.length == snippet_names.uniq.length
end