Class: ATDIS::Models::Info

Inherits:
ATDIS::Model show all
Defined in:
lib/atdis/models/info.rb

Instance Attribute Summary

Attributes inherited from ATDIS::Model

#attributes, #attributes_before_type_cast, #json_left_overs, #json_load_error, #timezone, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ATDIS::Model

attribute_keys, attribute_names, cast, cast_datetime, cast_geojson, cast_integer, cast_string, cast_uri, hash_symbols_to_string, #initialize, interpret, #json_errors, #json_errors_in_children, #json_errors_local, #json_left_overs_is_empty, #json_loaded_correctly!, partition_by_used, read_json, read_url, read_url_raw, #used_attribute?

Constructor Details

This class inherits a constructor from ATDIS::Model

Class Method Details

.url_encoded?(str) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
# File 'lib/atdis/models/info.rb', line 73

def self.url_encoded?(str)
  url_encoded = true
  str.each_char do |c|
    # These characters are the valid ones in a url encoded string
    url_encoded = false unless c =~ /[a-zA-Z0-9\-_.~%+]/
  end
  url_encoded
end

Instance Method Details

#dat_id_is_url_encoded!Object

TODO: Validate contents of estimated_cost



67
68
69
70
71
# File 'lib/atdis/models/info.rb', line 67

def dat_id_is_url_encoded!
  return unless dat_id && !Info.url_encoded?(dat_id)

  errors.add(:dat_id, ErrorMessage.new("should be url encoded", "4.3.1"))
end

#notification_dates_consistent!Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/atdis/models/info.rb', line 92

def notification_dates_consistent!
  if notification_start_date_before_type_cast && notification_end_date_before_type_cast.blank?
    errors.add(
      :notification_end_date,
      ErrorMessage["can not be blank if notification_start_date is set", "4.3.1"]
    )
  end
  if notification_start_date_before_type_cast.blank? && notification_end_date_before_type_cast
    errors.add(
      :notification_start_date,
      ErrorMessage["can not be blank if notification_end_date is set", "4.3.1"]
    )
  end
  return unless notification_start_date &&
                notification_end_date &&
                notification_start_date > notification_end_date

  errors.add(
    :notification_end_date,
    ErrorMessage["can not be earlier than notification_start_date", "4.3.1"]
  )
end


82
83
84
85
86
87
88
89
90
# File 'lib/atdis/models/info.rb', line 82

def related_apps_url_format
  return unless related_apps.respond_to?(:all?) &&
                !related_apps.all? { |url| url.to_s =~ %r{atdis\/1.0\/[^\/]+\.json} }

  errors.add(
    :related_apps,
    ErrorMessage.new("contains url(s) not in the expected format", "4.3.1")
  )
end