Class: CombineHashtags::Profile
- Inherits:
-
Object
- Object
- CombineHashtags::Profile
- Defined in:
- lib/combine_hashtags/profile.rb
Overview
Profile class to instantiate a user's profile and load their IG content from JSON stored locally
Instance Attribute Summary collapse
-
#posts ⇒ Object
Returns the value of attribute posts.
Instance Method Summary collapse
-
#destroy ⇒ Object
remove existing profile data.
-
#initialize(file_path) ⇒ Profile
constructor
loads json files to create profile and posts.
- #load_file ⇒ Object
- #load_posts ⇒ Object
-
#update(file_path) ⇒ Object
update profile with remaining json files.
Constructor Details
#initialize(file_path) ⇒ Profile
loads json files to create profile and posts
14 15 16 17 |
# File 'lib/combine_hashtags/profile.rb', line 14 def initialize(file_path) @posts = [] update(file_path) end |
Instance Attribute Details
#posts ⇒ Object
Returns the value of attribute posts.
11 12 13 |
# File 'lib/combine_hashtags/profile.rb', line 11 def posts @posts end |
Instance Method Details
#destroy ⇒ Object
remove existing profile data
47 48 49 50 51 |
# File 'lib/combine_hashtags/profile.rb', line 47 def destroy puts "removing current files" string = "#{ENV["STORAGE_PATH"]}*.json" `rm #{string}` end |
#load_file ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/combine_hashtags/profile.rb', line 19 def load_file if File.file?(@file_path) file = File.read(@file_path) @json_data = JSON.parse(file) else puts "file #{@file_path} not found" end end |
#load_posts ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/combine_hashtags/profile.rb', line 28 def load_posts @json_data["data"].map do |post| post_url = post["permalink"] img_url = post["media_url"] caption = post["caption"] || "" = post["timestamp"] @posts << CombineHashtags::Post.new(post_url, img_url, caption, ) end end |
#update(file_path) ⇒ Object
update profile with remaining json files
40 41 42 43 44 |
# File 'lib/combine_hashtags/profile.rb', line 40 def update(file_path) @file_path = file_path load_file load_posts end |