Class: Decidim::Geo::GeoDatasourceType
- Inherits:
-
Api::Types::BaseObject
- Object
- Api::Types::BaseObject
- Decidim::Geo::GeoDatasourceType
- Includes:
- SanitizeHelper
- Defined in:
- lib/decidim/api/geo_datasource_type.rb
Instance Method Summary collapse
- #banner_image ⇒ Object
- #component_id ⇒ Object
- #coordinates ⇒ Object
- #description ⇒ Object
- #end_time ⇒ Object
- #geom ⇒ Object
- #has_coordinates? ⇒ Boolean
- #has_geo_location? ⇒ Boolean
- #id ⇒ Object
- #latitude ⇒ Object
- #link ⇒ Object
- #location ⇒ Object
- #longitude ⇒ Object
- #participatory_space_id ⇒ Object
- #participatory_space_type ⇒ Object
- #scope ⇒ Object
- #short_description ⇒ Object
- #start_time ⇒ Object
- #title ⇒ Object
- #truncate_translated(value, chars = 2800) ⇒ Object
- #type ⇒ Object
Instance Method Details
#banner_image ⇒ Object
88 89 90 91 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 88 def return object.attached_uploader(:banner_image).url(only_path: true) if object.respond_to?(:banner_image) return object..first.url if object.respond_to?(:attachments) && object..first end |
#component_id ⇒ Object
33 34 35 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 33 def component_id object.component.id if object.respond_to?(:component) end |
#coordinates ⇒ Object
93 94 95 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 93 def coordinates {latitude: latitude, longitude: longitude} if has_coordinates? end |
#description ⇒ Object
60 61 62 63 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 60 def description return truncate_translated(object.body) if object.respond_to?(:body) return truncate_translated(object.description) if object.respond_to?(:description) end |
#end_time ⇒ Object
101 102 103 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 101 def end_time object.end_time if object.respond_to?(:end_time) end |
#geom ⇒ Object
115 116 117 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 115 def geom RGeo::GeoJSON.encode(object.shapedata.geom) if (object.respond_to?(:shapedata) && !object.shapedata.nil?) end |
#has_coordinates? ⇒ Boolean
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 132 def has_coordinates? ( has_geo_location? && !location.latitude.nil? && !location.longitude.nil? ) || ( object.respond_to?(:latitude) && object.respond_to?(:longitude) && !object.latitude.nil? && !object.longitude.nil? ) end |
#has_geo_location? ⇒ Boolean
123 124 125 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 123 def has_geo_location? object.respond_to?(:decidim_geo_space_location) end |
#id ⇒ Object
29 30 31 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 29 def id object.id end |
#latitude ⇒ Object
105 106 107 108 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 105 def latitude return location.latitude if has_geo_location? object.latitude end |
#link ⇒ Object
45 46 47 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 45 def link Decidim::ResourceLocatorPresenter.new(object).path(anchor: "DecidimGeo") end |
#location ⇒ Object
127 128 129 130 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 127 def location return nil unless has_geo_location? object.decidim_geo_space_location end |
#longitude ⇒ Object
110 111 112 113 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 110 def longitude return location.longitude if has_geo_location? object.longitude end |
#participatory_space_id ⇒ Object
37 38 39 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 37 def participatory_space_id return object.component.participatory_space_id if object.respond_to?(:component) end |
#participatory_space_type ⇒ Object
41 42 43 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 41 def participatory_space_type return object.component.participatory_space_type if object.respond_to?(:component) end |
#scope ⇒ Object
119 120 121 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 119 def scope object.scope if object.respond_to?(:scope) end |
#short_description ⇒ Object
54 55 56 57 58 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 54 def short_description return truncate_translated(object.short_description, 250) if object.respond_to?(:short_description) return truncate_translated(object.body, 250) if object.respond_to?(:body) return truncate_translated(object.description, 250) if object.respond_to?(:description) end |
#start_time ⇒ Object
97 98 99 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 97 def start_time object.start_time if object.respond_to?(:start_time) end |
#title ⇒ Object
49 50 51 52 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 49 def title return object.title if object.respond_to?(:title) return object.name if object.respond_to?(:name) end |
#truncate_translated(value, chars = 2800) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 65 def truncate_translated(value, chars=2800) value.each do |key, v| if v.is_a?(Hash) value[key] = truncate_translated(v, chars) else value[key] = Rails::Html::FullSanitizer.new.sanitize( Decidim::HtmlTruncation.new( Decidim::ContentProcessor.render( v ), max_length: 2800, tail: "…", count_tags: false, count_tail: false, tail_before_final_tag: false ).perform ).html_safe end end value end |
#type ⇒ Object
25 26 27 |
# File 'lib/decidim/api/geo_datasource_type.rb', line 25 def type object.class.name end |