forked from Terrastories/terrastories
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate out media and row decorators
- Loading branch information
1 parent
649b88e
commit e1df6a6
Showing
5 changed files
with
121 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class FileImport::PlaceRowDecorator | ||
METHODS_EXCEPT = [:media, :to_h] | ||
def initialize(row) | ||
@row = row.map { |_, value| value.to_s } | ||
end | ||
|
||
def name | ||
at(0) | ||
end | ||
|
||
def type_of_place | ||
at(1) | ||
end | ||
|
||
def description | ||
at(2) | ||
end | ||
|
||
def region | ||
at(3) | ||
end | ||
|
||
def long | ||
at(4) | ||
end | ||
|
||
def lat | ||
at(5) | ||
end | ||
|
||
def media | ||
::PlacePhotoDecorator.new(at(6).strip) | ||
end | ||
|
||
def to_h | ||
(public_methods(false) - METHODS_EXCEPT).inject({}) do |accumulator, method_name| | ||
accumulator[method_name] = public_send(method_name) | ||
accumulator | ||
end | ||
end | ||
|
||
private | ||
|
||
def at(index) | ||
@row[index] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class PlacePhotoDecorator | ||
def initialize(filename) | ||
@filename = filename | ||
end | ||
|
||
def attachable? | ||
File.exist?(path) | ||
end | ||
|
||
def blob_data | ||
if attachable? | ||
{io: File.open(path), filename: @filename} | ||
end | ||
end | ||
|
||
private | ||
|
||
def path | ||
Rails.root.join(::Place::MEDIA_PATH, @filename) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name,type_of_place,description,region,long,lat,media | ||
Iacitata,Community Center,"Iacitata is a restaurant and cultural space that hosts education around indigenous food and farming.",brazil,-48.502270,-1.454980,amazon.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters