This commit is contained in:
9
lib/notare/nodes/base.rb
Normal file
9
lib/notare/nodes/base.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class Base
|
||||
# Base class for all document nodes
|
||||
end
|
||||
end
|
||||
end
|
||||
38
lib/notare/nodes/image.rb
Normal file
38
lib/notare/nodes/image.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class Image < Base
|
||||
attr_reader :path, :width_emu, :height_emu, :rid, :filename
|
||||
|
||||
EMUS_PER_INCH = 914_400
|
||||
EMUS_PER_CM = 360_000
|
||||
DEFAULT_DPI = 96
|
||||
|
||||
def initialize(path, rid:, width_emu:, height_emu:)
|
||||
super()
|
||||
@path = path
|
||||
@rid = rid
|
||||
@width_emu = width_emu
|
||||
@height_emu = height_emu
|
||||
@filename = "image#{rid.delete_prefix("rId")}.#{extension}"
|
||||
end
|
||||
|
||||
def extension
|
||||
case File.extname(@path).downcase
|
||||
when ".png" then "png"
|
||||
when ".jpg", ".jpeg" then "jpeg"
|
||||
else raise ArgumentError, "Unsupported image format: #{File.extname(@path)}"
|
||||
end
|
||||
end
|
||||
|
||||
def content_type
|
||||
extension == "png" ? "image/png" : "image/jpeg"
|
||||
end
|
||||
|
||||
def doc_pr_id
|
||||
rid.delete_prefix("rId").to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/notare/nodes/list.rb
Normal file
20
lib/notare/nodes/list.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class List < Base
|
||||
attr_reader :items, :type, :num_id
|
||||
|
||||
def initialize(type:, num_id:)
|
||||
super()
|
||||
@type = type
|
||||
@num_id = num_id
|
||||
@items = []
|
||||
end
|
||||
|
||||
def add_item(item)
|
||||
@items << item
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/notare/nodes/list_item.rb
Normal file
20
lib/notare/nodes/list_item.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class ListItem < Base
|
||||
attr_reader :runs, :list_type, :num_id
|
||||
|
||||
def initialize(runs = [], list_type:, num_id:)
|
||||
super()
|
||||
@runs = runs
|
||||
@list_type = list_type
|
||||
@num_id = num_id
|
||||
end
|
||||
|
||||
def add_run(run)
|
||||
@runs << run
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
19
lib/notare/nodes/paragraph.rb
Normal file
19
lib/notare/nodes/paragraph.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class Paragraph < Base
|
||||
attr_reader :runs, :style
|
||||
|
||||
def initialize(runs = [], style: nil)
|
||||
super()
|
||||
@runs = runs
|
||||
@style = style
|
||||
end
|
||||
|
||||
def add_run(run)
|
||||
@runs << run
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
18
lib/notare/nodes/run.rb
Normal file
18
lib/notare/nodes/run.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class Run < Base
|
||||
attr_reader :text, :bold, :italic, :underline, :style
|
||||
|
||||
def initialize(text, bold: false, italic: false, underline: false, style: nil)
|
||||
super()
|
||||
@text = text
|
||||
@bold = bold
|
||||
@italic = italic
|
||||
@underline = underline
|
||||
@style = style
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
18
lib/notare/nodes/table.rb
Normal file
18
lib/notare/nodes/table.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class Table < Base
|
||||
attr_reader :rows
|
||||
|
||||
def initialize
|
||||
super
|
||||
@rows = []
|
||||
end
|
||||
|
||||
def add_row(row)
|
||||
@rows << row
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
18
lib/notare/nodes/table_cell.rb
Normal file
18
lib/notare/nodes/table_cell.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class TableCell < Base
|
||||
attr_reader :runs
|
||||
|
||||
def initialize
|
||||
super
|
||||
@runs = []
|
||||
end
|
||||
|
||||
def add_run(run)
|
||||
@runs << run
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
18
lib/notare/nodes/table_row.rb
Normal file
18
lib/notare/nodes/table_row.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Notare
|
||||
module Nodes
|
||||
class TableRow < Base
|
||||
attr_reader :cells
|
||||
|
||||
def initialize
|
||||
super
|
||||
@cells = []
|
||||
end
|
||||
|
||||
def add_cell(cell)
|
||||
@cells << cell
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user