Class: Myun2::TwitterShell::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/myun2/twitter_shell/profile.rb

Defined Under Namespace

Classes: Loader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Profile

Returns a new instance of Profile.



18
19
20
# File 'lib/myun2/twitter_shell/profile.rb', line 18

def initialize(params = {})
  @data = params
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/myun2/twitter_shell/profile.rb', line 4

def data
  @data
end

Class Method Details

.default_profile_pathObject



41
42
43
# File 'lib/myun2/twitter_shell/profile.rb', line 41

def self.default_profile_path
  File.join(root_dir, 'profile')
end

.load(path = nil) ⇒ Object



32
33
34
35
# File 'lib/myun2/twitter_shell/profile.rb', line 32

def self.load(path = nil)
  return unless data = Loader.load(path || default_profile_path)
  new(data)
end

.root_dirObject



37
38
39
# File 'lib/myun2/twitter_shell/profile.rb', line 37

def self.root_dir
  File.expand_path('~/.twsh')
end

Instance Method Details

#profile_pathObject



45
46
47
# File 'lib/myun2/twitter_shell/profile.rb', line 45

def profile_path
  @profile_path ||= Profile.default_profile_path
end

#saveObject



22
23
24
25
26
27
28
29
30
# File 'lib/myun2/twitter_shell/profile.rb', line 22

def save
  Dir.mkdir Profile.root_dir unless File.exist?(Profile.root_dir)

  open(profile_path, "w") do |f|
    @data.each do |key,value|
      f.puts key.to_s + "=" + value.to_s
    end
  end
end