Class Simplepay::Support::Field
In: lib/simplepay/support/field.rb
Parent: Object
RuntimeError Error Service Standard Marketplace Donation Subscription MarketplacePolicy Interval SubscriptionPeriod BillingFrequency Comparable Field Service Epoch Currency Amount Boolean ResponseStatusCode Services Authentication FormHelper NotificationHelper RailsHelper Helpers Interval Currency Support Boolean Simplepay dot/f_2.png

Represents a data field which will ultimately populate a Simple Pay form. These fields are often unique to their service.


<=>   new   required?   service_name   to_input   to_s  

Included Modules



ALLOWED_OPTIONS = [:as, :class, :required, :value]


name  [R]  The name of the field used in your local program (may be different than the service name)
service  [R]  The parent service of the field

Public Class methods

name:Name which is used when referring to this field in the code.
options:An optional hash of field options.


as:Overrides the name when used by the service to the exact string or symbol (camelized) given.
class:Delegate the value mechanics to a separate class.
required:Tells whether or not this field is required for its service.
value:Set the value of the field at initialization.

Example, :required => true, :as => 'ExAmplE'), :class => Simplepay::Support::Boolean, :value => true)


# File lib/simplepay/support/field.rb, line 37
      def initialize(service, name, options)
        @service, @name, @options = service, name, normalize_options!(options)
        @delegate   = options[:class]
        @value      = nil
        self.value  = options[:value] if options[:value]

Public Instance methods

Sorting is based solely by service_name.


# File lib/simplepay/support/field.rb, line 101
      def <=>(o)
        self.service_name <=> o.service_name

Returns true if the field is required for the service.


# File lib/simplepay/support/field.rb, line 65
      def required?
        @options[:required] ? true : false

Returns the name of the field used by the service. This may be different than the Ruby name given to the field.

Symbol names (or :as options) are camelized. If this is not desired, use a String, instead.


# File lib/simplepay/support/field.rb, line 51
      def service_name
        source = @options[:as] || @name
        case source
        when Symbol

Converts a Field into an HTML HIDDEN INPUT element as a string.


# File lib/simplepay/support/field.rb, line 72
      def to_input
        raise(RequiredFieldMissing, "Missing Required Field value for #{name}") if required? && value.blank?
        value.blank? ? '' : html_input_tag

Alias for service_name