File: prefix.rb

package info (click to toggle)
ruby-wisper 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 276 kB
  • sloc: ruby: 1,231; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Wisper
  module ValueObjects #:nodoc:
    # Prefix for notifications
    #
    # @example
    #   Wisper::ValueObjects::Prefix.new nil    # => ""
    #   Wisper::ValueObjects::Prefix.new "when" # => "when_"
    #   Wisper::ValueObjects::Prefix.new true   # => "on_"
    class Prefix < String
      class << self
        attr_accessor :default
      end

      # @param [true, nil, #to_s] value
      #
      # @return [undefined]
      def initialize(value = nil)
        super "#{ (value == true) ? default : value }_"
        replace "" if self == "_"
      end

      private

      def default
        self.class.default || 'on'
      end
    end # class Prefix
  end # module ValueObjects
end # module Wisper