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
13 14 15 16 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 13 def assert(source) source = parse(source) unless source.is_a?(self) source end |
.parse(path) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 18 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
31 32 33 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 31 def change?(other) type_change?(other) || path_change?(other) end |
#path_change?(other) ⇒ Boolean
35 36 37 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 35 def path_change?(other) path..to_s != other.path..to_s end |
#to_s ⇒ Object
39 40 41 42 43 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 39 def to_s r = path.to_s r = "#{type.to_s.upcase}:#{r}" if type.present? r end |
#type_change?(other) ⇒ Boolean
45 46 47 48 49 50 |
# File 'lib/ehbrs_ruby_utils/vg/wii/wit/path.rb', line 45 def type_change?(other) return false if other.type.blank? return true if type.blank? type != other.type end |