Class: EhbrsRubyUtils::Vg::Wii::Wit::Path
- Inherits:
-
Object
- Object
- EhbrsRubyUtils::Vg::Wii::Wit::Path
- Defined in:
- lib/ehbrs_ruby_utils/vg/wii/wit/path.rb
Constant Summary collapse
- WIT_PATH_PATTERN =
/\A(?:([a-z0-9]+):)?(.+)\z/i.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #change?(other) ⇒ Boolean
- #path_change?(other) ⇒ Boolean
- #to_s ⇒ Object
- #type_change?(other) ⇒ Boolean
Class Method Details
.assert(source) ⇒ Object
11 12 13 14 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 11 def assert(source) source = parse(source) unless source.is_a?(self) source end |
.parse(path) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 16 def parse(path) WIT_PATH_PATTERN .match(path) .if_present { |m| new(m[1], m[2]) } .if_blank { raise "\"#{WIT_PATH_PATTERN}\" does not match \"#{path}\"" } end |
Instance Method Details
#change?(other) ⇒ Boolean
29 30 31 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 29 def change?(other) type_change?(other) || path_change?(other) end |
#path_change?(other) ⇒ Boolean
33 34 35 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 33 def path_change?(other) path..to_s != other.path..to_s end |
#to_s ⇒ Object
37 38 39 40 41 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 37 def to_s r = path.to_s r = "#{type.to_s.upcase}:#{r}" if type.present? r end |
#type_change?(other) ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 43 def type_change?(other) return false if other.type.blank? return true if type.blank? type != other.type end |