Class: EgovUtils::Fileuid::Snippet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lengthObject

Returns the value of attribute length

Returns:

  • (Object)

    the current value of length



4
5
6
# File 'lib/egov_utils/fileuid.rb', line 4

def length
  @length
end

#mandatoryObject

Returns the value of attribute mandatory

Returns:

  • (Object)

    the current value of mandatory



4
5
6
# File 'lib/egov_utils/fileuid.rb', line 4

def mandatory
  @mandatory
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/egov_utils/fileuid.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



4
5
6
# File 'lib/egov_utils/fileuid.rb', line 4

def type
  @type
end

Instance Method Details

#length_to_regex_partObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/egov_utils/fileuid.rb', line 29

def length_to_regex_part
  case length
  when 1, nil
    ''
  when :any
    mandatory? ? "+" : "*"
  when Array
    "{#{length[0]},#{length[1]}}"
  when Numeric
    "{#{length}}"
  else
    length
  end
end

#mandatory?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/egov_utils/fileuid.rb', line 6

def mandatory?
  mandatory.nil? ? true : mandatory
end

#static?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/egov_utils/fileuid.rb', line 10

def static?
  type == :static
end

#to_regex_sObject



44
45
46
# File 'lib/egov_utils/fileuid.rb', line 44

def to_regex_s
  type_to_regex_part + length_to_regex_part
end

#type_to_regex_partObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/egov_utils/fileuid.rb', line 14

def type_to_regex_part
  case type
  when String
    type
  when :integer
    "\\d"
  when :word
    "\\w"
  when :static
    name
  else
    raise "Unsuported fileuid snippet type #{type}"
  end
end