Class: Apkstats::Entity::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/apkstats/entity/feature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, not_required: false, implied_reason: nil) ⇒ Feature

Returns a new instance of Feature.



11
12
13
14
15
16
# File 'lib/apkstats/entity/feature.rb', line 11

def initialize(name, not_required: false, implied_reason: nil)
  @name = name
  # cast to Boolean
  @not_required = not_required == true
  @implied_reason = implied_reason || nil
end

Instance Attribute Details

#implied_reasonObject (readonly)

String?



9
10
11
# File 'lib/apkstats/entity/feature.rb', line 9

def implied_reason
  @implied_reason
end

#nameObject (readonly)

String



6
7
8
# File 'lib/apkstats/entity/feature.rb', line 6

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
39
40
# File 'lib/apkstats/entity/feature.rb', line 36

def ==(other)
  return if !other || other.class != self.class

  to_s == other.to_s
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/apkstats/entity/feature.rb', line 42

def eql?(other)
  to_s.eql?(other.to_s)
end

#hashObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/apkstats/entity/feature.rb', line 46

def hash
  h = not_required? ? 1 : 0
  h *= 31
  h += name.hash

  if implied_reason
    h *= 31
    h += implied_reason.hash
  end

  h
end

#implied?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/apkstats/entity/feature.rb', line 22

def implied?
  @implied_reason
end

#not_required?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/apkstats/entity/feature.rb', line 18

def not_required?
  @not_required
end

#to_sObject



26
27
28
29
30
31
32
33
34
# File 'lib/apkstats/entity/feature.rb', line 26

def to_s
  if implied?
    "#{name} (#{implied_reason})"
  elsif not_required?
    "#{name} (not-required)"
  else
    name
  end
end