Class: Mulang::Inspection::Target

Inherits:
Object
  • Object
show all
Includes:
Compacted
Defined in:
lib/mulang/inspection/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Compacted

#as_json

Constructor Details

#initialize(type, value = nil) ⇒ Target

Returns a new instance of Target.



6
7
8
9
# File 'lib/mulang/inspection/target.rb', line 6

def initialize(type, value=nil)
  @type = type
  @value = value
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/mulang/inspection/target.rb', line 4

def type
  @type
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/mulang/inspection/target.rb', line 4

def value
  @value
end

Class Method Details

.anyoneObject



67
68
69
# File 'lib/mulang/inspection/target.rb', line 67

def self.anyone
  new(:anyone)
end

.named(value) ⇒ Object



63
64
65
# File 'lib/mulang/inspection/target.rb', line 63

def self.named(value)
  new(:named, value)
end

.parse(target_s) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mulang/inspection/target.rb', line 11

def self.parse(target_s)
  if target_s.blank?
    nil
  elsif target_s == '*'
    anyone
  elsif target_s.start_with? '^'
    new :except, target_tail(target_s)
  elsif target_s.start_with? '~'
    new :like, target_tail(target_s)
  elsif target_s.start_with? '='
    named target_tail(target_s)
  else
    unknown target_s
  end
end

.target_tail(target_s) ⇒ Object



55
56
57
# File 'lib/mulang/inspection/target.rb', line 55

def self.target_tail(target_s)
  target_s[1..-1]
end

.unknown(value) ⇒ Object



59
60
61
# File 'lib/mulang/inspection/target.rb', line 59

def self.unknown(value)
  new(:unknown, value)
end

Instance Method Details

#i18n_suffixObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mulang/inspection/target.rb', line 42

def i18n_suffix
  case type
  when :anyone
    nil
  when :except
    "_except"
  when :like
    "_like"
  else
    "_named"
  end
end

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mulang/inspection/target.rb', line 27

def to_s
  case type
  when  :anyone
    '*'
  when :except
    "^#{value}"
  when :like
    "~#{value}"
  when :named
    "=#{value}"
  else
    value
  end
end