Class: Musedown::Score

Inherits:
Object
  • Object
show all
Defined in:
lib/musedown.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prebuilt) ⇒ Score

Returns a new instance of Score.



11
12
13
14
15
16
# File 'lib/musedown.rb', line 11

def initialize(prebuilt)
    @score_file = nil
    @relative_score_file = nil
    @relative_image_file = nil
    @prebuilt = prebuilt
end

Instance Attribute Details

#prebuiltObject (readonly)

Returns the value of attribute prebuilt.



9
10
11
# File 'lib/musedown.rb', line 9

def prebuilt
  @prebuilt
end

#relative_image_fileObject

Returns the value of attribute relative_image_file.



8
9
10
# File 'lib/musedown.rb', line 8

def relative_image_file
  @relative_image_file
end

#relative_score_fileObject

Returns the value of attribute relative_score_file.



7
8
9
# File 'lib/musedown.rb', line 7

def relative_score_file
  @relative_score_file
end

#score_fileObject

Returns the value of attribute score_file.



6
7
8
# File 'lib/musedown.rb', line 6

def score_file
  @score_file
end

Instance Method Details

#build(command) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/musedown.rb', line 18

def build(command)
    begin
        image_file = "#{@score_file.gsub(".mscz", "-mscz")}.png"
        result = `#{command} #{@score_file} -o #{image_file}`
    rescue Errno::ENOENT => error
        puts("⚠️ Error building #{@score_file}: #{error}")
    end

    if $?.success?
        if !prebuilt
            @relative_image_file = @relative_score_file.sub(/.*\K\.mscz/, "-mscz-1.png")
        end
    else
        puts("⚠️ Failed to convert #{@score_file}")
    end
    return $?.success?
end