Module: SmsAero::Types
- Defined in:
- lib/sms_aero/types/phone.rb,
lib/sms_aero/types/future.rb,
lib/sms_aero/types/channel.rb,
lib/sms_aero/types/digital.rb,
lib/sms_aero/types/birthday.rb,
lib/sms_aero/types/password.rb,
lib/sms_aero/types/sign_status.rb,
lib/sms_aero/types/filled_string.rb
Constant Summary collapse
- Phone =
Describes a valid phone containing digits without lead zeros
Strict::String.constrained(format: /\A\d{11,13}\z/) .constructor do |value| value.to_s.scan(/\d/).join[/[^0].*/].to_s end
- Future =
Describes coercible Unix time in future
Strict::Int.constructor do |value| begin error = TypeError.new "#{value.inspect} is not a valid time in future" time = value.to_time if value.respond_to? :to_time time ||= ::Time.parse(value.to_s) unless value.is_a? Numeric number = time.to_i number > ::Time.now.to_i ? number : raise(error) rescue raise error end end
- Channel =
Describes acceptable channel codes
Coercible::Int.constrained included_in: [1, 2, 3, 4, 6]
- Digital =
Converts any value to either 1 or 0 flag for digital sending channel
Strict::Int.constructor { |value| value ? 1 : 0 }
- Birthday =
Describes a user’s birthday in year-month-date format Accepts dates, times, datetimes, and strings parceable to dates
Strict::String .constrained(format: /\A\d{4}-\d{2}-\d{2}\z/) .constructor do |value| begin date = value.to_date if value.respond_to? :to_date date ||= ::Date.parse(value.to_s) date.strftime "%Y-%m-%d" rescue raise TypeError, "#{value.inspect} cannot be coerced to date" end end
- Password =
Strict::String.constructor do |value| OpenSSL::Digest::MD5.new.hexdigest(value) end
- SignStatus =
Describes statuses of the sign
Strict::String.constrained included_in: %w( accepted approved rejected pending )
- FilledString =
Coercible::String.constrained(filled: true)