Class: Friends::Location

Inherits:
Object
  • Object
show all
Extended by:
Serializable
Defined in:
lib/friends/location.rb

Constant Summary collapse

SERIALIZATION_PREFIX =
"- ".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

deserialize

Constructor Details

#initialize(name:) ⇒ Location

Returns a new instance of Location.

Parameters:

  • name (String)

    the name of the location


26
27
28
# File 'lib/friends/location.rb', line 26

def initialize(name:)
  @name = name
end

Instance Attribute Details

#n_activitiesObject


46
47
48
# File 'lib/friends/location.rb', line 46

def n_activities
  defined?(@n_activities) ? @n_activities : 0
end

#nameObject

Returns the value of attribute name


30
31
32
# File 'lib/friends/location.rb', line 30

def name
  @name
end

Class Method Details

.deserialization_expectationRegexp

Returns the string of what we expected during deserialization.

Returns:

  • (Regexp)

    the string of what we expected during deserialization


21
22
23
# File 'lib/friends/location.rb', line 21

def self.deserialization_expectation
  "[Location Name]"
end

.deserialization_regexRegexp

Returns the regex for capturing groups in deserialization.

Returns:

  • (Regexp)

    the regex for capturing groups in deserialization


15
16
17
18
# File 'lib/friends/location.rb', line 15

def self.deserialization_regex
  # Note: this regex must be on one line because whitespace is important
  /(#{SERIALIZATION_PREFIX})?(?<name>.+)/
end

Instance Method Details

#regex_for_nameRegexp

Returns the regex used to match this location's name in an activity description.

Returns:

  • (Regexp)

    the regex used to match this location's name in an activity description


39
40
41
# File 'lib/friends/location.rb', line 39

def regex_for_name
  Friends::RegexBuilder.regex(@name)
end

#serializeString

Returns the file serialization text for the location.

Returns:

  • (String)

    the file serialization text for the location


33
34
35
# File 'lib/friends/location.rb', line 33

def serialize
  "#{SERIALIZATION_PREFIX}#{@name}"
end