class Book

Constants

DIMENSIONS
GROUPINGS
ROLES

Attributes

namespace[RW]

Public Instance Methods

content() click to toggle source
# File lib/iatelier/models/book.rb, line 66
def content
        markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
        return markdown.render(content_raw.to_s.force_encoding(Encoding::UTF_8))
end
content_raw() click to toggle source
# File lib/iatelier/models/book.rb, line 52
def content_raw
        unless self.id.nil?
                path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s + '/main.md'
                puts 'triving to retrive the content from the path = ' + path.to_s
                if File.exists? path
                        return File.open(path).read
                else
                        return nil
                end
        else
                return nil
        end
end
convert(string) click to toggle source
# File lib/iatelier/models/book.rb, line 119
def convert string
        if string.kind_of? String
                require 'json'
                return JSON.parse(string);
        end
        return string;
end
dimensions() click to toggle source
# File lib/iatelier/models/book.rb, line 37
def dimensions
        self.class::DIMENSIONS
end
get_asset(params) click to toggle source
# File lib/iatelier/models/book.rb, line 204
def get_asset params
        path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s + '/'
        return File.open(path + params[:asset], 'r')
end
groupings() click to toggle source
# File lib/iatelier/models/book.rb, line 40
def groupings
       self.class::GROUPINGS
end
individuals(requested_role) click to toggle source
# File lib/iatelier/models/book.rb, line 47
def individuals requested_role
        @query = '`peopleables`.`role` = "' + requested_role.to_s + '"'
        self.peoples.includes(:peopleables).where(@query)
end
kind() click to toggle source
# File lib/iatelier/models/book.rb, line 30
def kind
        self.class.to_s
end
revise_description(params) click to toggle source
# File lib/iatelier/models/book.rb, line 151
def revise_description params
        self.description.update(value: params[:description])
end
revise_slug(params) click to toggle source
# File lib/iatelier/models/book.rb, line 144
def revise_slug params
        return self.slug.update(value: params[:slug])
end
revise_subtitle(params) click to toggle source
# File lib/iatelier/models/book.rb, line 137
def revise_subtitle params
        return self.subtitle.update(value: params[:subtitle])
end
revise_thumbnail(params) click to toggle source
# File lib/iatelier/models/book.rb, line 157
def revise_thumbnail params
end
revise_timestamp(params) click to toggle source
# File lib/iatelier/models/book.rb, line 168
def revise_timestamp params
        puts 'revising timestamp'
        unless self.timestamp.nil?
                puts 'we found some > updating'
                self.timestamp.update({
                        draft: params[:timestamp][:draft],
                        publish: params[:timestamp][:publish],
                        amend: params[:timestamp][:amend]
                })
        else
                puts 'initiating new ones!'
                self.setup_timestamp params
        end
end
revise_title(params) click to toggle source
# File lib/iatelier/models/book.rb, line 130
def revise_title params
        return self.title.update(value: params[:title])
end
roles() click to toggle source
# File lib/iatelier/models/book.rb, line 43
def roles
        self.class::ROLES
end
setup_description(params) click to toggle source
# File lib/iatelier/models/book.rb, line 148
def setup_description params
        self.build_description({value: params[:description]})
end
setup_slug(params) click to toggle source
# File lib/iatelier/models/book.rb, line 141
def setup_slug params
        return self.build_slug({value: params[:slug]})
end
setup_subtitle(params) click to toggle source
# File lib/iatelier/models/book.rb, line 134
def setup_subtitle params
        return self.build_subtitle({value: params[:subtitle]})
end
setup_thumbnail(params) click to toggle source
# File lib/iatelier/models/book.rb, line 155
def setup_thumbnail params
end
setup_timestamp(params) click to toggle source
# File lib/iatelier/models/book.rb, line 160
def setup_timestamp params
        puts 'setting up timestamp'
        self.build_timestamp({
                draft: params[:timestamp][:draft],
                publish: params[:timestamp][:publish],
                amend: params[:timestamp][:amend]
        })
end
setup_title(params) click to toggle source
# File lib/iatelier/models/book.rb, line 127
def setup_title params
        return self.build_title({value: params[:title]})
end
store_attachment(params) click to toggle source
# File lib/iatelier/models/book.rb, line 195
def store_attachment params
        path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s + '/'
        if !params.get(:file).nil?
                Dir.mkdir(path) unless File.exists?(path)
                File.open(path + params[:file][:filename], 'wb') do |file|
                        file.write params[:file][:tempfile].read
                end
        end
end
sync_content(params) click to toggle source
# File lib/iatelier/models/book.rb, line 183
def sync_content params
        path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s
        Dir.mkdir(path) unless File.exists?(path)
        File.open(path + '/main.md', 'w+') do |file|
                file.puts params[:content]
        end
        puts 'updating loc!!! ' + self.id.to_s
        self.update(loc: self.id.to_s)
        self.save
        puts self.loc.to_s
end
sync_individuals(params) click to toggle source
# File lib/iatelier/models/book.rb, line 83
def sync_individuals params
        @roles = params[:people]
        puts "this is what we have:" + @roles.to_s
        @roles.each do |role, individuals|
                individuals = individuals.split ', '
                @existings = self.individuals(role)
                puts "here is the new output = " + @existings.to_s
                @existings.each do |instance|
                        @delete = true
                        individuals.each do |individual|
                                if instance.identifier == individual
                                        @delete = false
                                end
                                if @delete
                                        instance.delete
                                end
                        end
                end
                individuals.each do |individual|
                        if People.find_by(identifier: individual)
                                puts "identifier exists"
                                if self.individuals(role).find_by(identifier: individual)
                                        puts "this record already exists = " + self.individuals(role).where(identifier: individual).to_s
                                else
                                        self.peopleables.create(role: role, people: People.find_by(identifier: individual))
                                end
                        else
                                puts "a whole new person entry"
                                person = People.create(identifier: individual)
                                self.peopleables.create(role: role, people: People.find_by(identifier: individual))
                        end
                        # DELETING THE DELETED ASSOCIATIONS!!!
                end
        end
end
sync_keywords(params) click to toggle source
# File lib/iatelier/models/book.rb, line 71
def sync_keywords params
        @nkeys = []
        @keywords = params[:keywords].split ', '

        @keywords.each do |keyword|
                @new_keyword = Keyword.find_or_create_by(:word => keyword)
                @nkeys << @new_keyword
        end

        self.keywords = @nkeys
end
uniq() click to toggle source
# File lib/iatelier/models/book.rb, line 33
def uniq
        self.class.to_s + self.id.to_s
end