Class: HyBook::Album

Inherits:
Object
  • Object
show all
Defined in:
lib/hybook/type/album.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Album

Returns a new instance of Album.



10
11
12
13
# File 'lib/hybook/type/album.rb', line 10

def initialize( title )
  @title      = title
  @sections  = []      # sections (for pictures)
end

Instance Attribute Details

#sectionsObject

Returns the value of attribute sections.



8
9
10
# File 'lib/hybook/type/album.rb', line 8

def sections
  @sections
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/hybook/type/album.rb', line 7

def title
  @title
end

Class Method Details

.create_from_folder(root, opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hybook/type/album.rb', line 20

def self.create_from_folder( root, opts={} )
  dirs = Dir[ "#{root}/**/" ]  ## get all folders n subfolder
  ## pp dirs

  title = opts[:title ] || 'Untitled'

  album = Album.new( title )

  dirs.each do |dir|
    section_title =  dir[ root.length+1..-2 ]  # cut off ROOT_DIR plus leading and trailing /
    files = Dir[ "#{dir}/*.{png,gif,jpg}" ]

    ## fix: use logger
    puts "dir: #{dir}, title: #{section_title}, files: #{files.size}"
    next if files.size == 0   # skip if no image files in folder
  
    section = Section.new( section_title )
    album.sections << section

    ## puts "files:"
    ## pp files

    files.each do |filename|
      extname      = File.extname( filename )
      basename     = File.basename( filename, extname )   # NB: remove extname (that is, suffix e.g. .png,.jpg,.gif etc.)

      picture_title = basename   # use basename
      picture_path  = filename   # TODO/FIX: strip off leading root path ?? why? why not???
      ### rename path to source or src or file or filename - why? why not??


      picture = Picture.new( picture_title, picture_path )
      section.pictures << picture
    end
  end
  album   # return album struct
end