class Ulysses::Group

Attributes

dirname[R]

Public Class Methods

new(info_file_path) click to toggle source
# File lib/ulysses/group.rb, line 6
def initialize(info_file_path)
  @info_file = info_file_path
  @dirname   = File.dirname(@info_file)
end

Public Instance Methods

children() click to toggle source
# File lib/ulysses/group.rb, line 19
def children
  @children ||= parse_children
end
Also aliased as: groups
display_name() click to toggle source
# File lib/ulysses/group.rb, line 15
def display_name
  @display_name ||= info['displayName'].content
end
groups()
Alias for: children
info() click to toggle source
# File lib/ulysses/group.rb, line 11
def info
  @info ||= parse_info
end
reload() click to toggle source
# File lib/ulysses/group.rb, line 28
def reload
  @info, @children, @sheets = nil
end
sheets() click to toggle source
# File lib/ulysses/group.rb, line 24
def sheets
  @sheets ||= parse_sheets
end

Private Instance Methods

parse_children() click to toggle source
# File lib/ulysses/group.rb, line 52
def parse_children
  return [] unless info['childOrder']
  info['childOrder']
      .children
      .select { |child| child.element? }
      .map { |child| Group.new File.join(@dirname, child.content, 'Info.ulgroup') }
end
parse_info() click to toggle source
# File lib/ulysses/group.rb, line 34
def parse_info
  xml  = Nokogiri::XML File.read(@info_file)
  dict = xml.xpath('//dict')
             .children
             .select { |child| child.element? }
             .map { |child| child.name == 'key' ? child.content : child }
  Hash[*dict]
end
parse_sheets() click to toggle source
# File lib/ulysses/group.rb, line 43
def parse_sheets
  return [] unless info['sheetClusters']
  info['sheetClusters']
      .children
      .select { |c| c.element? && c.name == 'array' }
      .map { |i| i.children.find { |c| c.element? && c.name == 'string' }.content }
      .map { |dir| Sheet.new File.join(@dirname, dir) }
end