Class: Mumukit::Inspection::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/inspection/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value = nil) ⇒ Target

Returns a new instance of Target.


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

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

Instance Attribute Details

#typeObject

Returns the value of attribute type.


2
3
4
# File 'lib/mumukit/inspection/target.rb', line 2

def type
  @type
end

#valueObject

Returns the value of attribute value.


2
3
4
# File 'lib/mumukit/inspection/target.rb', line 2

def value
  @value
end

Class Method Details

.anyoneObject


65
66
67
# File 'lib/mumukit/inspection/target.rb', line 65

def self.anyone
  new(:anyone)
end

.named(value) ⇒ Object


61
62
63
# File 'lib/mumukit/inspection/target.rb', line 61

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

.parse(target_s) ⇒ Object


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

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


53
54
55
# File 'lib/mumukit/inspection/target.rb', line 53

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

.unknown(value) ⇒ Object


57
58
59
# File 'lib/mumukit/inspection/target.rb', line 57

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

Instance Method Details

#i18n_suffixObject


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mumukit/inspection/target.rb', line 40

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

#to_sObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mumukit/inspection/target.rb', line 25

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